本文介绍了如何设置QMainWindow作为模态一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用QMainWindow为我的项目的GUI开发。我遇到的一个问题是阻止所有其他可见窗口获取输入,而一个正在操作。
我如何声明一个特定的窗口为模态?
我尝试使用 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();
}
解决方案
w2-> setWindowModality(Qt :: ApplicationModal)
w2-> show();
也可以使用QWidget并建立工具栏,菜单栏和状态栏。
I am using QMainWindow for GUI development of my project..One problem I am Stuck with is blocking all other visible windows from getting input, while one is in operation.
I can not use QDialog.Because rich features of QMainWindow is required.
How can I declare a particular window as modal?
I tried with QWidget::setWindowMOdality()
.
Here is a demo program, what I tried but it didnt work.
#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();
}
解决方案
Try setting the modal flag first, then show the widget.
w2->setWindowModality(Qt::ApplicationModal);
w2->show();
Also you could use QWidget and build the toolbar, menu bar and status bar.
这篇关于如何设置QMainWindow作为模态一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!