颜色选择对话框
#include <QColorDialog>
#include <QDebug>
QColor color = QColorDialog: : getColor ( Qt: : white, this, tr ( "颜色对话框" ) , QColorDialog: : ShowAlphaChannel) ;
qDebug ( ) << "color.red():" << color. red ( ) ;
qDebug ( ) << "color.green():" << color. green ( ) ;
qDebug ( ) << "color.blue():" << color. blue ( ) ;
qDebug ( ) << "color.alpha():" << color. alpha ( ) ;
文件对话框
#include <QFileDialog>
QString fileName = QFileDialog: : getOpenFileName ( this, tr ( "文件对话框" ) , "D:\\Tinkle" , tr ( "file(*docx *rar);;(*jpg *png)" ) ) ;
QStringList filenames = QFileDialog: : getOpenFileNames ( this, tr ( "文件对话框" ) , "D:\\Tinkle" , tr ( "file(*docx *rar)" ) ) ;
字体设置对话框
#include <QFontDialog>
bool ok;
QFont font = QFontDialog: : getFont ( & ok, this) ;
if ( ok)
{
ui-> pushButton-> setFont ( font) ;
}
else
qDebug ( ) << "没有设置字体" ;
输入对话框
#include <QInputDialog>
bool ok;
QString string = QInputDialog: : getText ( this, tr ( "获取字符串" ) , tr ( "Lable" ) , QLineEdit: : Normal, tr ( "admin" ) , & ok) ;
int num = QInputDialog: : getInt ( this, tr ( "获取整数" ) , tr ( "Lable" ) ,
100 , - 50 , 900 , 10 , & ok) ;
double d = QInputDialog: : getDouble ( this, tr ( "获取浮点数" ) , tr ( "Lable " ) , 0.00 , - 50 , 900 , 3 , & ok) ;
QStringList items;
items<< "apple" << "ball" << "cat" << "dog" ;
QString item = QInputDialog: : getItem ( this, tr ( "获取条目" ) , tr ( "Lable" ) , items, 0 , true, & ok) ;
if ( ok)
qDebug ( ) << "items:" << items<< "\nitem:" << item;
消息对话框
#include <QMessageBox>
int ret1 = QMessageBox: : question ( this, "title" , "question" , QMessageBox: : Yes, QMessageBox: : No) ;
if ( ret1 == QMessageBox: : Yes)
qDebug ( ) << "yes" ;
int ret2 = QMessageBox: : information ( this, "title" , "info" , QMessageBox: : Ok) ;
if ( ret2 == QMessageBox: : Ok)
qDebug ( ) << "yes" ;
int ret3 = QMessageBox: : warning ( this, "title" , "warn" , QMessageBox: : Abort) ;
if ( ret3 == QMessageBox: : Abort)
qDebug ( ) << "yes" ;
int ret4 = QMessageBox: : critical ( this, "title" , "warn" , QMessageBox: : YesAll) ;
if ( ret4 == QMessageBox: : YesAll)
qDebug ( ) << tr ( "错误" ) ;
QMessageBox: : about ( this, tr ( "title" ) , tr ( "about ..." ) ) ;
进度对话框
#include <QProgressDialog>
QProgressDialog dlg ( tr ( "process" ) , tr ( "cancle" ) , 0 , 50000 , this) ;
dlg. setWindowTitle ( tr ( "Title" ) ) ;
dlg. setWindowModality ( Qt: : WindowModal) ;
dlg. show ( ) ;
for ( int i = 0 ; i< 50000 ; i++ )
{
dlg. setValue ( i) ;
QCoreApplication: : processEvents ( ) ;
if ( dlg. wasCanceled ( ) )
break ;
}
dlg. setValue ( 50000 ) ;
错误信息对话框
#include <QErrorMessage>
QErrorMessage * errorDlg = new QErrorMessage ( this) ;
errorDlg-> setWindowTitle ( "Title" ) ;
errorDlg-> showMessage ( "error" ) ;
向导对话框
. h文件
#include <QWizard>
private:
QWizardPage * createPage1 ( ) ;
QWizardPage * createPage2 ( ) ;
QWizardPage * createPage3 ( ) ;
. cpp文件
void MainWindow: : on_pushButton_clicked ( )
{
QWizard wizard ( this) ;
wizard. setWindowTitle ( "guide" ) ;
wizard. addPage ( createPage1 ( ) ) ;
wizard. addPage ( createPage2 ( ) ) ;
wizard. addPage ( createPage3 ( ) ) ;
wizard. exec ( ) ;
}
QWizardPage * MainWindow: : createPage1 ( )
{
QWizardPage * page = new QWizardPage;
page-> setTitle ( "introduce" ) ;
return page;
}
QWizardPage * MainWindow: : createPage2 ( )
{
QWizardPage * page = new QWizardPage;
page-> setTitle ( "info" ) ;
return page;
}
QWizardPage * MainWindow: : createPage3 ( )
{
QWizardPage * page = new QWizardPage;
page-> setTitle ( "end" ) ;
return page;
}