1. Modal and non-modal differences: Non-modal windows can be operated at the same time. Modal windows can only be used after the top window is closed.
// The widget and dialog windows are displayed simultaneously. The non-modal qdialog * dialog = new qdialog (this); dialog-> show ();
// The widget and dialog windows are displayed simultaneously. The modal qdialog * dialog = new qdialog (this); dialog-> setmodal (true); dialog-> show ();
// Display the dialog window. The widget window is displayed only after the dialog window is closed. The modal qdialog Dialog (this); dialog.exe C (); 2. the modal window is used for switching multiple windows, first, a dialog is displayed. Click the touch button on the window to hide the window. The widget window and dialog are displayed. CPP void mydialog: on_pushbutton_clicked () {accept (); // qdialog: accepted;} Main. CPP mywidget W;
Mydialog dialog; // create a mydialog Class Object
If(dialog.exe C () = qdialog: accepted) {// judge the dialog execution result W. show (); // if the "Enter main interface" button is pressed, return a.exe C () on the main interface is displayed; // The program runs normally} widget. CPP // display the previous window and hide the current window void mywidget: on_pushbutton_clicked () {// close the main interface first. In fact, it is hidden and close () is not actually exited ();
// Create a mydialog object mydialog DLG;
// If you press the "Enter main window" button, the main interface is displayed again. // otherwise, the program will exit if(dlg.exe C () = qdialog:: accepted) show () ;}3, standard window 1. Color dialog box void mywidget: on_pushbutton_clicked () {// create the object qcolordialog Dialog (QT: Red, this );
// Display the Alpha option dialog. setoption (qcolordialog: showalphachannel );
// Run the dialog box dialog.exe C () in modal mode ();
// Obtain the current color qcolor color = dialog. currentcolor ();
// Output color information qdebug () <"color:" <color;} 2. File Dialog Box void mywidget: on_pushbutton_2_clicked () {qstringlist filenames = qfiledialog :: getopenfilenames (this, TR ("file dialog box"), "F:", TR ("image file (* PNG * JPG); text file (* txt )")); qdebug () <"filenames:" <filenames;} // getopenfilenames: You can obtain multiple file names and return values qstringlist filenames // getopenfilename: only one file name can be returned. qstring filename 3. Font dialog box // font dialog box void mywidget: on_pushbutton_3_clicked () {// indicates whether the "OK" button bool OK is pressed;
// Obtain the selected font qfont font = qfontdialog: getfont (& OK, this );
// If you press the "OK" button, set the "font dialog box" button to use the new font. // If you press the "cancel" button, output the information if (OK) UI-> pushbutton_3-> setfont (font); // set the pushbutton_3 font else qdebug () <tr ("No font selected! ");}
4. Dialog Box MessageBox int ret1 = qmessagebox: Question (this, TR ("question dialog box"), TR ("do you know QT? "), Qmessagebox: Yes, qmessagebox: No); // qmessagebox: Yes, qmessagebox: No is the return value of the button if (ret1 = qmessagebox: Yes) {...} else {...} 5. Progress dialog box // void mywidget: on_pushbutton_6_clicked () {qprogressdialog Dialog (TR ("file copy progress"), TR ("cancel"), this );
// Set the window title dialog. setwindowtitle (TR ("Progress dialog box "));
// Set the dialog box to modal dialog. setwindowmodality (QT: windowmodal); dialog. Show ();
// Demonstrate the replication progress (INT I = 0; I <50000; I ++ ){
// Set the current value of the progress bar dialog. setvalue (I );
// Avoid freezing the interface. qcoreapplication: processevents ();
// Press the cancel button to interrupt if (dialog. wascanceled () break ;}
// In this way, 100% is displayed, because a few dialog. setvalue (50000); qdebug () <tr ("copying ends! ");}
4. Use the label to set the image and play GIF animations. // set the image UI-> label-> setpixmap (qpixmap ("h: /study Res/Qt creator Res/src/03/3-8/logo.png "); // play GIF qmovie * movie = new qmovie (" h: /study Res/Qt creator Res/src/03/3-8/OK .gif ");
// Add the animation UI to the tag-> label-> setmovie (movie );
// Start playing movie-> Start (); 5. Multiple interface components of qstackedwidget can have multiple interfaces, and each interface can have its own parts. Only one interface can be displayed at a time. You need to use qcombobox or qlistwidget to select the interface and add item to qlistwidget, add the interface insert page-> after current page to qstackedwidget and associate currentrowchange of qlistwidget with setcurrentindex of qstackedwidget. 6. Change the frameshape attribute of the qtoolbox drawer control to box // set the first drawer. icon qicon iconfriend (": /New/ICO/images/friend. ICO "); toolbox-> setitemicon (0, iconfriend );