窗体部件之Dialogs
来源:互联网 发布:淘宝app抢购需要刷新吗 编辑:程序博客网 时间:2024/04/30 12:18
dialog.cpp
#include "dialog.h"#include "ui_dialog.h"#include <QDebug>#include <QColorDialog>#include <QFileDialog>#include <QFontDialog>#include <QInputDialog>#include <QMessageBox>#include <QProgressDialog>#include <QErrorMessage>Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog){ ui->setupUi(this);}Dialog::~Dialog(){ delete ui;}void Dialog::on_btnAccept_clicked(){ accept();}void Dialog::on_pushButton_clicked(){ //QColor color = QColorDialog::getColor(Qt::red, this, tr("颜色对话框")); //QColor color = QColorDialog::getColor(Qt::red, this, tr("color")); //QColor color = QColorDialog::getColor(Qt::red, this, tr("color"), QColorDialog::ShowAlphaChannel); QColorDialog dialog(Qt::red, this); dialog.setOption(QColorDialog::ShowAlphaChannel); dialog.exec(); QColor color = dialog.currentColor(); qDebug() << "color:" << color;}void Dialog::on_pushButton_2_clicked(){ //QString fileName = QFileDialog::getOpenFileName(this, tr("file"), "F:", tr("picture file(*png *jpg)")); //QString fileName = QFileDialog::getOpenFileName(this, tr("file"), "F:", tr("picture file(*png *jpg);;txt file( *txt)")); QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("file"), "F:", tr("picture file(*png *jpg)")); qDebug() << "fileNames:" << fileNames;}void Dialog::on_pushButton_3_clicked(){ bool ok; qDebug() << ok; QFont font = QFontDialog::getFont(&ok, this); if (ok){ ui->pushButton_3->setFont(font); qDebug() << "select ok!"; }else qDebug() << tr("no font selected!");}void Dialog::on_pushButton_4_clicked(){ bool ok; QString string = QInputDialog::getText(this, tr("input string"), tr("please input usrName: ") , QLineEdit::Normal, tr("admin"), &ok); if (ok) qDebug() << "string:" << string; int value1 = QInputDialog::getInt(this, tr("input integer"), tr("please input an integer between -1000 and 1000") , 100, -1000, 1000, 10, &ok); if (ok) qDebug() << "value1:" << value1; int value2 = QInputDialog::getDouble(this, tr("input floater"), tr("please input an floater between -1000 and 1000") , 0.00, -1000, 1000, 2, &ok); if (ok) qDebug() << "value2:" << value2; QStringList items; items << tr("item1") << ("item2"); QString item = QInputDialog::getItem(this, tr("input item"), tr("please input an item") , items, 0, true, &ok); if (ok) qDebug() << "item:" << item;}void Dialog::on_pushButton_5_clicked(){ int ret1 = QMessageBox::question(this, tr("question"), tr("do you know Qt?") ,QMessageBox::Yes, QMessageBox::No); if(ret1 == QMessageBox::Yes) qDebug() << tr("question!"); int ret2 = QMessageBox::information(this, tr("information"), tr("this is a book about Qt") ,QMessageBox::Ok); if(ret2 == QMessageBox::Ok) qDebug() << tr("information!"); int ret3 = QMessageBox::warning(this, tr("warning"), tr("cannot cancel in advance") ,QMessageBox::Abort); if(ret3 == QMessageBox::Abort) qDebug() << tr("warning!"); int ret4 = QMessageBox::critical(this, tr("seriously critical"), tr("find critical! close all the file!") ,QMessageBox::YesAll); if(ret4 == QMessageBox::YesAll) qDebug() << tr("critical!"); QMessageBox::about(this, tr("about"), tr("devote to Qt universally!"));}void Dialog::on_pushButton_6_clicked(){ QProgressDialog dialog(tr("file copy progress"), tr("cancel"), 0, 50000, this); dialog.setWindowTitle("progress"); dialog.setWindowModality(Qt::WindowModal); dialog.show(); for(int i = 0; i < 50000; i++) { dialog.setValue(i); QCoreApplication::processEvents(); if( dialog.wasCanceled() ) break; } dialog.setValue(50000); qDebug() << tr("copy finished!");}void Dialog::on_pushButton_7_clicked(){ QErrorMessage *dialog = new QErrorMessage(this); dialog->setWindowTitle("error"); dialog->showMessage("error message!");}QWizardPage *Dialog::createpage1(){ QWizardPage *page = new QWizardPage; page->setTitle("introduce"); return page;}QWizardPage *Dialog::createpage2(){ QWizardPage *page = new QWizardPage; page->setTitle("choose information"); return page;}QWizardPage *Dialog::createpage3(){ QWizardPage *page = new QWizardPage; page->setTitle("finished"); return page;}void Dialog::on_pushButton_8_clicked(){ QWizard wizard(this); wizard.setWindowTitle(tr("wizard")); wizard.addPage(createpage1());; wizard.addPage(createpage2());; wizard.addPage(createpage3());; wizard.exec();}
阅读全文
0 0
- 窗体部件之Dialogs
- 窗体部件之Buddy
- 窗体部件之QActionGroup
- 窗体部件之QButtonGroup
- 窗体部件之QCompleter
- 窗体部件之QDesktopWidget
- 窗体部件之QDockWidget
- 窗体部件之QMdiArea
- 窗体部件之QWizard
- 窗体部件之QSizeGrip
- 窗体部件之QSystemTrayIcon
- 窗体部件之QToolBar
- 窗体部件之QToolBox
- 窗体部件之QCheckBox
- 窗体部件之QComboBox
- 窗体部件之QMenu
- 窗体部件之QTabWidget
- 窗体部件之QProgressBar
- Java内存区域与内存溢出
- [Leetcode] 215. Kth Largest Element in an Array 解题报告
- java项目中使用Sigar获取系统信息
- 关于SharedPreferences apply() 和commit() 区别
- uintX-t
- 窗体部件之Dialogs
- 黄秀杰--小程序实现选择图片九宫格带预览
- Mac下安装Python3.5
- 004. Spring 注入参数
- HTML5 CSS3专题 纯CSS打造相册效果
- 贝叶斯分类器
- 算法竞赛知识提要3
- 关于部署war包到服务器存在代理的问题
- linux最小环境中没有办法输入中文