Qt modal dialog box and non-Modal Dialog Box

Source: Internet
Author: User

 

The concepts of modal dialog and modeless dialog are not exclusive to QT and exist on different platforms. It is also called a mode dialog box or a mode-free dialog box. A modal dialog box means that a user cannot interact with other windows of the same application until the dialog box is closed. When a non-modal dialog box is opened, you can choose to interact with the dialog box or other windows of the application.

In QT, there are two ways to display a dialog box. One is to use the exec () method, which always displays the dialog box in the mode; the other is to use the show () method, it enables the dialog box to display both modal and non-modal modes, and determines whether it is a modal or non-modal attribute of the dialog box.

In QT, the modal and non-modal dialog boxes of QT are determined by the modal attribute. Let's take a look at the modal attribute. Its definition is as follows:

Modal: by default, the value of this attribute in the dialog box is false. In this case, the show () method is used to display the non-modal dialog box. If the attribute value is set to true, the mode dialog box is set to set the qwidget: windowmodality attribute to QT: applicationmodal.

When the exec () method is used to display the dialog box, the setting of the modal attribute value is ignored and the dialog box is set as the modal dialog box.

The setmodal () method is generally used to set the modal attribute of the dialog box.

Let's summarize the method for setting the dialog box as a modal mode.

◆ To set it as a modal dialog box, the simplest method is to use the exec () method. The sample code is as follows:

Mydialog mydlg; mydlg.exe C (); you can also use the show () method. The sample code is as follows:

Mydialog mydlg; mydlg. setmodal (true); mydlg. Show ();

◆ To set a non-modal dialog box, you must use the show () method. The sample code is as follows:

Mydialog mydlg; mydlg. setmodal (false );
// Or
Mydlg. setmodal ();
Mydlg. Show ();

Note: This article is copied online, the original link is: http://wangjiajun53880.blog.163.com/blog/static/11700139420110319573769/

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.