颜色对话框
void oneForm::doProcessColorClicked()
{
QColor color = QColorDialog::getColor(Qt::red,this,"Colorful",QColorDialog::ShowAlphaChannel);
qDebug()<<"color"<<color;
}
文件对话框
void oneForm::doProcessFileClicked()
{
QStringList filenames = QFileDialog::getOpenFileNames(this,"文件对话框",
"D:","图片文件(*.png *.jpg);;文档(*.pdf)");
qDebug()<<"filenames"<<filenames;
}
字体对话框
void oneForm::doProcessFontClicked()
{
bool ok;
QFont font = QFontDialog::getFont(&ok,this);
if(ok)
{
ui->btn_front->setFont(font);
}
else
{
qDebug()<<"未选择字体!";
}
}
输入对话框
void oneForm::doProcessInputClicked()
{
bool ok;
QString text = QInputDialog::getText(this,"输入对话框","用户名",QLineEdit::Normal,QDir::home().dirName(),&ok);
if(ok)
{
qDebug()<<"text"<<text;
}
int value1 = QInputDialog::getInt(this,"输入整型的数字","Int类型",100,-1000,1000,2,&ok);
if(ok)
{
qDebug()<<"value1"<<value1;
}
int value2 = QInputDialog::getDouble(this,"输入整型的数字","Double类型",100,-1000,1000,0.1,&ok);
if(ok)
{
qDebug()<<"value2"<<value2;
}
QStringList items;
items<<"张三"<<"王五"<<"李白";
QString item = QInputDialog::getItem(this,"输入条目对话框","请选择一个条目",items,0,true,&ok);
if(ok)
{
qDebug()<<"item"<<item;
}
}
消息对话框
void oneForm::doProcessMsgClicked()
{
int ret1 = QMessageBox::question(this,"问题对话框","你了解我吗?",
QMessageBox::Yes,QMessageBox::No);
if(ret1 == QMessageBox::Yes)
{
qDebug()<<"QMessageBox::Yes";
}
int ret2 = QMessageBox::information(this,"提示对话框","这是一本计算机的相关书籍。",
QMessageBox::Yes,QMessageBox::No);
if(ret2 == QMessageBox::Yes)
{
qDebug()<<"QMessageBox::Yes";
}
int ret3 = QMessageBox::warning(this,"警告","不可以跳过这一步哦!",
QMessageBox::Abort);
if(ret3 == QMessageBox::Abort)
{
qDebug()<<"QMessageBox::Abort";
}
int ret4 = QMessageBox::critical(this,"严重错误对话框","现在关闭所有对话框!",
QMessageBox::YesAll);
if(ret4 == QMessageBox::YesAll)
{
qDebug()<<"QMessageBox::YesAll";
}
QMessageBox::aboutQt(this,"关于Qt");
}
进度条对话框
void oneForm::doProcessProBarClicked()
{
QProgressDialog dialog("文件复制进度","取消",0,50000,this);
dialog.setWindowTitle("进度对话框");
dialog.setWindowModality(Qt::WindowModal);
dialog.show();
for(int i=0;i<50000;i++)
{
dialog.setValue(i);
QCoreApplication::processEvents();
if(dialog.wasCanceled())
{
qDebug()<<"文件复制取消";
return;
}
}
dialog.setValue(50000);
qDebug()<<"文件复制结束!";
}
错误消息对话框
void oneForm::doProcessErrMsgClicked()
{
errordig->setWindowTitle("错误消息对话框");
errordig->showMessage("这是一条错误消息!");
}
向导对话框
void oneForm::doProcessGuideClicked()
{
QWizard wizard(this);
wizard.setWindowTitle("向导对话框");
wizard.addPage(createPage1());
wizard.addPage(createPage2());
wizard.addPage(createPage3());
wizard.exec();
}
QWizardPage *oneForm::createPage1()
{
QWizardPage *page=new QWizardPage(this);
page->setTitle("介绍");
return page;
}
QWizardPage *oneForm::createPage2()
{
QWizardPage *page=new QWizardPage(this);
page->setTitle("用户选择信息");
return page;
}
QWizardPage *oneForm::createPage3()
{
QWizardPage *page=new QWizardPage(this);
page->setTitle("结束");
return page;
}
private:
QWizardPage *createPage1();
QWizardPage *createPage2();
QWizardPage *createPage3();