Tag:qfile suffix parent option pre etc bsp files user
The Standard file dialog box has the following functions: QString qfiledialog::getopenfilename ( * parent=0, Const QString &caption=QString (), const QString &dir=QString (), const QString &filter=QString (), *selectfiler=0,// the filter selected by the user is returned by this parameter Option option=0// Select the format of the display file name, which displays both the directory and the file name by default )
voidWidget::btn_click () {/*getopenfilename () open window is modal window*/ /*parameters not included*/ //QString s=qfiledialog::getopenfilename (); /*with parameters * The first parameter is the pointer to its parent window * The second parameter is the name of the open window * The third parameter dir, which is the default open Directory when the dialog box is displayed, * "." represents the program run directory, "/" represents the root directory of the current drive letter (Windows, Linux/is the root directory), * can also be platform-related, such as "c:\\" and so on; * For example, I want to open the Data folder under the program run directory as the default open path, * Here should be written "./data/", if you want to have a default selected file, * Then add the file name after the directory: "./data/teaser.graph" * Fourth parameter filter, is the name of the dialog box suffix filter, * For example, we use "Image Files (*.jpg *.png)" Let it only display suffix name is JP A file of G or PNG. * If you need to use multiple filters, use ";;" (Here is a semicolon) split , * e.g. "JPEG Files" (*.jpg);; PNG Files (*.png) "; * Fifth parameter selectedfilter, is the default selection of the filter; * The sixth parameter options, is the dialog box parameter settings, * such as only display folder, etc., its value is enum qfiled Ialog::option, each option can be used | Operations together. */QString S=qfiledialog::getopenfilename ( This,"Open the name of the window","/","C + + file (*.cpp);; C file (*.c);; Head file (*.h)"); /*the user clicked OK*/ if(!S.isempty ()) { This-Setwindowtitle (s); }}
The Standard Color dialog box functions as follows GetColor () function is a static function of the standard color dialog box Qcolordialog class, which returns the color value selected by the user, the following is the form of the GetColor () function: Qcolor getColor ( const qcolor &initial=Qt::whiye, *parent=0)
void Widget::btn_click () { /* header file needs to contain Qcolor and Qcolordialog*/ * * The first parameter sets the default color, optional * Second parameter parent window pointer, optional */ qcolor C=qcolordialog:: GetColor (Qt::blue,this);}
The Standard Font dialog box functions as follows GetFont () function is a static function of the Standard Font dialog box Qfontdialog class, which returns the font selected by the user, the following is the form of GetFont () function Qfont GetFont ( BOOL *OK, *parent=0)
voidWidget::btn_click () {BOOLOK; /** GetFont () The first parameter must be selected*/Qfontdialog::getfont (&OK); /*The user clicks OK, returns True, the user clicks Cancel, returns false*/ if(OK) {Setwindowtitle ("user clicks OK"); }Else{setwindowtitle ("User Click Cancel"); }}
Qmessagebox class question () function Standardbutton qmessagebox::question ( *parent,// message box parent window pointer const QString & Title,// message box title bar const QString & Text , message box text hint information standardbuttons buttons=Ok, standardbutton defaultbutton=No)
voidWidget::btn_click () {/** The third parameter is the Settings dialog box has a few buttons, * The fourth parameter is the Setting dialog box is the default selected button is which*/ if(Qmessagebox::question ( This,"Message title","Message Content Entity", qmessagebox::ok| Qmessagebox::cancel,qmessagebox::ok) = =Qmessagebox::ok) { /*the user clicked OK*/Setwindowtitle ("OK"); }Else{setwindowtitle ("NO"); }}
QT dialog box