Qt modal and non-modal

Source: Internet
Author: User

Modal is when the child window pops up, the focus is always forced to focus on the child window, as long as the child window does not exit, the focus will not be released. The non-modal is just the opposite.

From the thread perspective, the modal Subwindow thread is blocked, and the parent and child windows each have a thread, and when the child window is created, the parent thread blocks off the quilt thread, the non-modal thread is not blocked, and the parent and child threads can run in parallel.

In the modal of Qt, the Qdialog exec () method is used mainly:

12345678910 SonDialog dlg(this);intres = dlg.exec();if(res == QDialog::Accepted){    QMessageBox::information(this"INFORMATION""You clicked OK button!");}if(res == QDialog::Rejected){    QMessageBox::information(this"INFORMATION""You clicked CANCEL button!");}

The return value of the exec () determines which button the user is triggering.

Non-modal, mainly used in the Qdialog Show () method:

123 SonDialog *dlg;dlg = newSonDialog(this);dlg->show();

Transferred from: http://blog.csdn.net/zhy282289/article/details/6741356

Http://www.cnblogs.com/weiweiqiao99/archive/2011/05/19/2050887.html

The relationship between modal and non-modal is recorded first:

Both 1.QDialog and qwidget can be modal and non-modal.

EXEC (), Show ()

Whether the modal is independent of the two functions, only related to window properties

SetAttribute (Qt::wa_showmodal, True) or setwindowmodality (qt::applicationmodal), modifying whether it is modal.

For Qdialog You can also use his member function Setmodal (TRUE) (Dlg->show modal);

EXEC () is modal because he first set the window properties: SetAttribute () again show (see source)

2. Whether a qwidget is a form or a control on a form regardless of the parent class, only related to the window tag: setwindowflags (Qt::window)

Qpushbutton * ppushbtn = new Qpushbutton (this);

Qpushbutton * ppushbtn = new Qpushbutton (when there is no parent class, the constructor adds a Qt::window tag)

Qdialog * dlg = new Qdialog (this), regardless of whether or not the parent class is a form, because QT is passed when a parameter is transmitted to the Qwidget: the:D ialog tag.

So make the form only with Setwindowflags (Qt::window);

Qt modal and non-modal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.