2

我正在使用 aQProgressDialog来显示我的initializeGL()功能的进度,但小窗口显示为未上漆......这是简化的代码:

QProgressDialog barTest("Wait","Ok", 0, 100, this);

barTest.move(400,400);

barTest.show();

for(int i = 0; i < 100; i++)
{
    barTest.setValue(i);
    qDebug() << i;
}

我在跑Mac OS 10.8

4

1 回答 1

1

问题是,只要您正在执行代码(例如for循环),窗口的绘制事件就会卡在 Qt 的事件循环中。

如果要处理绘制事件,可以使用QApplication::processEvents

for(int i = 0; i < 100; i++)
{
    barTest.setValue(i);
    qDebug() << i;

    // handle repaints (but also any other event in the queue)
    QApplication::processEvents();
}

根据循环的速度,您可能会发现仅更新每 10% 就足够了,例如:

for(int i = 0; i < 100; i++)
{
    barTest.setValue(i);
    qDebug() << i;

    // handle repaints (but also any other event in the queue)
    if(i % 10 == 0) QApplication::processEvents();
}
于 2013-06-24T10:53:18.417 回答