1
我正在使用QMainWindow进行我的项目的GUI开发..我遇到的一个问题是阻止所有其他可见窗口获取输入,而一个正在运行。如何将QMainWindow设置为模态?
我不能使用QDialog。因为QMainWindow的丰富功能是必需的。
我该如何声明特定窗口为模态?我试过QWidget::setWindowMOdality()
。
这是一个演示程序,我试过了,但没有奏效。
#include <QApplication>
#include <QMainWindow>
#include <QPushButton>
int main(int argc, char **argv){
QApplication a(argc, argv);
QMainWindow *w1 = new QMainWindow();
w1->resize(500,800);
w1->move(100,50);
w1->show();
QMainWindow *w2= new QMainWindow();
w2->resize(800,500);
w2->move(50,50);
w2->show();
w2->setWindowModality(Qt::ApplicationModal);
return a.exec();
}
很好,没错,谢谢+1 –