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/