0

我需要绘制简单的矩形,但是当我调用 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);
}
}
4

1 回答 1

0

你应该尝试添加

e->accept()

在paintEvent 函数的末尾。

于 2013-02-28T12:37:17.717 回答