How to set QMainWindow as the modal one?

我与影子孤独终老i 提交于 2019-12-12 09:49:40

问题


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();

}

回答1:


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.



来源:https://stackoverflow.com/questions/21326549/how-to-set-qmainwindow-as-the-modal-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!