我有一小段代码:
#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();
}
我显示QWidget
,在两秒钟后显示QMessageBox
。
如果我在显示弹出窗口时调整主窗口的大小,我的鼠标光标不会恢复正常(它会保持“调整窗口大小”的样子)并且界面完全冻结< / strong>即可。我无法关闭弹出窗口,我无法将鼠标移到任务栏上。
唯一的解决方案是使用 ALT + TAB 导航到Visual Studio并停止调试器。
系统(如果重要):
我的问题:
答案 0 :(得分:1)
根据Digia支持,这是一个错误。但是,它们提供了可接受的解决方法。
在QMessageBox::critical
之前,我们可以像这样添加ReleaseCapture();
:
#ifdef Q_OS_WIN
ReleaseCapture();
#endif
行为可以追溯到Qt 4.7(参见user3183610的评论)。窗口将恢复原始大小。