简体   繁体   English

QProgressDialog在initializeGL期间不绘制

[英]QProgressDialog doesn't paint during initializeGL

I'm using a QProgressDialog to display the progress of my initializeGL() function but the little window show up unpainted... Here's the simplified code : 我正在使用QProgressDialog来显示我的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;
}

I'm running Mac OS 10.8 我正在运行Mac OS 10.8

The problem is that the paint event for the window is stuck in Qt's Event Loop as long as you are executing code (eg the for loop). 问题在于,只要您正在执行代码(例如, for循环),该窗口的绘制事件就会卡在Qt的事件循环中。

If you want the paint events to be processed, you can use QApplication::processEvents : 如果要处理绘画事件,可以使用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();
}

Dependent on the quickness of the loop you might find it sufficient to update only each 10% for instance: 根据循环的速度,您可能发现仅更新例如每个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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM