Qt Painter不更新

时间:2013-02-28 12:30:08

标签: c++ qt

我需要绘制简单的rect但是当我调用update()函数时它不会做任何事情。这是我的代码:

...//this is called when button is pressed, when application loads nothing should be drawn.

    draw = true;
    update();
}

void MainWindow::paintEvent(QPaintEvent *e){
    QPainter painter(this);
    QLinearGradient lg(QPoint(20, 80), QPoint(215, 390));
    lg.setColorAt(0, Qt::white);
    lg.setColorAt(1, Qt::blue);
    QBrush brush(lg);
    painter.setPen(Qt::black);
    painter.setBrush(brush);
    if(draw == true){
    painter.drawRect(20, 80, 195, 300);
}
}

1 个答案:

答案 0 :(得分:0)

你应该尝试添加

e->accept()

在paintEvent函数的末尾。