当前位置: 代码迷 >> QT开发 >> mainwidow里面画图如何不出图
  详细解决方案

mainwidow里面画图如何不出图

热度:227   发布时间:2016-04-25 03:03:59.0
mainwidow里面画图怎么不出图
setwindow::setwindow(QWidget *parent) 
    :QMainWindow(parent)
{
    this->resize(900,700);//重新设置大小
    // 画一条直线
    QPainter painter(this);             // 创建QPainter一个对象
    QPen pen;
    //pen.setStyle(Qt::DashLine);
    pen.setColor(Qt::blue);           // 设置画笔为蓝色
    painter.setPen(pen);                // 设置画笔
    //画坐标轴系
    painter.translate(100,700);      //坐标原点定位于物理坐标的(100,700)
    painter.scale(1, -1);           //Y轴反向向上指
    painter.drawLine(0,0,700,0);     //画x轴
    painter.drawLine(0,0,0,-500);    //画y轴
    //画y轴左边刻度值
    painter.drawText(-100,-90,"100");
    painter.drawText(-200,-90,"200");
    painter.drawText(-300,-90,"300");
    painter.drawText(-400,-90,"400");
    painter.drawText(-500,-90,"500");
    painter.drawText(-600,-90,"600");
    //画x轴右边刻度值
    painter.drawText(100,-10,"64");
    painter.drawText(200,-10,"128");
    painter.drawText(300,-10,"192");
    painter.drawText(400,-10,"256");
    painter.drawText(500,-10,"320");
    painter.drawText(600,-10,"384");
    painter.drawText(700,-10,"448");
}
------解决思路----------------------
绘图部分放到paintEvent函数里
void QWidget::paintEvent ( QPaintEvent * event ) [virtual protected]

------解决思路----------------------
1. 绘制操作 必须在派生类重写的 paintEvent() 中进行
2. 派生并重写 QMainWindow的 paintEvent() 是不明智的行为,应该派生一个普通的QWidget
  相关解决方案