Question

I have this small piece of code:

#include <QApplication>
#include <QWidget>
#include <QBasicTimer>
#include <QMessageBox>

class MyWidget:public QWidget{
public:
    QBasicTimer timer;
protected:
    void timerEvent(QTimerEvent*e){
        if(e->timerId()==timer.timerId()){
            timer.stop();
            QMessageBox::critical(this,"Oups",
                                 "I hope you were not resizing the main window.");
            return;
        }
        QWidget::timerEvent(e);
    }
};

int main(int argc,char*argv[]){
    QApplication app(argc,argv);
    MyWidget w;
    w.timer.start(2000,&w);
    w.show();
    return app.exec();
}

I display a QWidget which displays a QMessageBox after two seconds. If I am resizing my main window when the popup is displayed, my mouse cursor does not come back to normal (it keeps a "resizing a Window" look) and the interface is completely frozen. I cannot close the popup and I cannot move my mouse over the Taskbar.

The only solution is to navigate with ALT+TAB to Visual studio and stop the debugger.

System (if it matters):

  • Windows 7 64 bit.
  • Visual Studio 2013 + Addin
  • Qt 5.3.0 alpha

My questions:

  • Is it a known bug?
  • Am I doing something wrong?
  • Is there a simple workaround?
Was it helpful?

Solution

According to Digia Support, this is a bug. However, they provide an acceptable workaround.

Just before the QMessageBox::critical we can add a ReleaseCapture(); like this:

#ifdef Q_OS_WIN
    ReleaseCapture();
#endif

The behavior goes back to Qt 4.7 though (cf comment from user3183610). The window will snap back to its original size.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top