窗体部件之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();}
原创粉丝点击