窗体部件之Dialogs

这里写图片描述

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值