• 5857阅读
  • 5回复

[讨论]widget显示问题? [复制链接]

上一主题 下一主题
离线tlcugb
 

只看楼主 倒序阅读 楼主  发表于: 2012-03-13

#include "geomodeldesigndialog.h"
#include <QPainter>
#include <QPen>
#include <QBrush>
#include <QColor>
#include <QVector>
#include <QLinearGradient>
GeoModelDesignDialog::GeoModelDesignDialog(QWidget *parent,GeoColorMap *clr)
: QDialog(parent)
{
ui.setupUi(this);
mClrmap = clr;
ui.mBackValueEdit->setText("1.70141E+038");
ui.mCurrentValueEdit->setText("1.70141E+038");
initColorBar();
connect(ui.mApplyBtn,SIGNAL(clicked()),this,SLOT(apply()));
}
GeoModelDesignDialog::~GeoModelDesignDialog()
{
}
void GeoModelDesignDialog::accept()
{
//new model
if(ui.mCurrentValueEdit->text().isEmpty()
  ||ui.mBackValueEdit->text().isEmpty())
  return;
ModelDesignInfo info;
info.current = ui.mCurrentValueEdit->text().toDouble();
info.back = ui.mBackValueEdit->text().toDouble();
emit upgrade(info);
this->hide();
}
void GeoModelDesignDialog::reject()
{
this->hide();
}
void GeoModelDesignDialog::apply()
{
//new model
if(ui.mCurrentValueEdit->text().isEmpty()
  ||ui.mBackValueEdit->text().isEmpty())
  return;
ModelDesignInfo info;
info.current = ui.mCurrentValueEdit->text().toDouble();
info.back = ui.mBackValueEdit->text().toDouble();
emit upgrade(info);
}

void GeoModelDesignDialog::initColorBar()
{
QPainter painter(ui.mColorBar);
painter.save();
drawColorBar(&painter);
drawLabel(&painter);
painter.restore();
}
void GeoModelDesignDialog::setColorMap(GeoColorMap *clr)
{
mClrmap = clr;
}
void GeoModelDesignDialog::drawColorBar(QPainter *painter)
{
if(!mClrmap)
  return;
painter->setRenderHint(QPainter::Antialiasing, true);
QRect barRect = ui.mColorBar->rect().adjusted(0,0,-5,0);
QLinearGradient linearGradient(0,0,barRect.width(),barRect.height());
//color number;
QVector<ClrMap> colors = mClrmap->clrMapLevels();
double minv = mClrmap->minValue();
double maxv = mClrmap->maxValue();
for(int i=0;i<colors.size();i++)
{
  linearGradient.setColorAt((colors.value-minv)/(maxv-minv), colors.color);
}
QPen pen(QBrush(linearGradient), barRect.width());
painter->setPen(pen);
pen.setCapStyle(Qt::FlatCap);
painter->setPen(pen);
painter->drawLine(barRect.width()/2, 0, barRect.width()/2, barRect.height());
pen.setWidth(0);
pen.setColor(Qt::black);
painter->setPen(pen);
painter->drawRect(barRect);
}
void GeoModelDesignDialog::drawLabel(QPainter *painter)
{
}

为什么ui.mColorBar不能显示
离线zzh12215
只看该作者 1楼 发表于: 2012-03-14
void GeoModelDesignDialog::drawColorBar(QPainter *painter)
{
if(!mClrmap)
  return;
......}
貌似你return了吧
离线tlcugb

只看该作者 2楼 发表于: 2012-03-14
回 1楼(zzh12215) 的帖子
这个在类创建过程中已经初始化了!
调试在那不会返回 的!
离线jdwx

只看该作者 3楼 发表于: 2012-03-14
回 2楼(tlcugb) 的帖子
如果你用QtCreator编译运行程序,就会发现下面的应用程序窗口里面会有提示。

Qt的绘图只能在paintEvent里面,其它的时间不能绘图。
发帖时要说明:操作系统、Qt版本、编译器,这样能更快的得到回复。
离线tlcugb

只看该作者 4楼 发表于: 2012-03-14
ok,问题解决了!
离线zzh12215
只看该作者 5楼 发表于: 2012-04-09
是我的错,误导人了
快速回复
限100 字节
 
上一个 下一个