#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDialog>
#include <QFileDialog>
#include <QColorDialog>
#include <QDebug>
#include <QFontDialog>
#include <QInputDialog>
#include <QMessageBox>
#include <QProgressDialog>
#include <QErrorMessage>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
errordlg = new QErrorMessage(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_colorpushButton_clicked()
{
//ARGB
//QColor color = QColorDialog::getColor(Qt::red,this,QObject::tr("颜色对话框"));
//qDebug() << color;
QColorDialog dialog(Qt::red,this);
//dialog.setOption(QColorDialog::ShowAlphaChannel);
dialog.exec();
QColor color = dialog.currentColor();
qDebug() << color;
}
void MainWindow::on_filepushButton_2_clicked()
{
QString str = QFileDialog::getOpenFileName(this,"文件选择对话框","D:",tr("图片文件(*jpg *png)"));
qDebug() << str;
}
void MainWindow::on_fontpushButton_3_clicked()
{
bool OK;
QFont font = QFontDialog::getFont(&OK,this);
if(OK)
{
qDebug() << font;
}
}
void MainWindow::on_inputpushButton_4_clicked()
{
QString str = QInputDialog::getText(this,"输入对话框","this is label");
qDebug() << str;
}
void MainWindow::on_messagepushButton_5_clicked()
{
int ret = QMessageBox::question(this,"问题对话框","你了解Qt吗?",QMessageBox::Yes,QMessageBox::No);
if(ret == QMessageBox::Yes)
{
qDebug() << "yes";
}
else{
qDebug() << "no";
}
int ret1 = QMessageBox::information(this,"提示对话框","学习QT",QMessageBox::Yes,QMessageBox::No);
if(ret1 == QMessageBox::Yes)
{
qDebug() << "yes";
}
else{
qDebug() << "no";
}
int ret2 = QMessageBox::warning(this,"警告对话框","停止学习QT",QMessageBox::Yes,QMessageBox::No);
if(ret2 == QMessageBox::Yes)
{
qDebug() << "yes";
}
else{
qDebug() << "no";
}
int ret3 = QMessageBox::critical(this,"严重错误对话框","立即停止!",QMessageBox::Yes,QMessageBox::No);
if(ret3 == QMessageBox::Yes)
{
qDebug() << "yes";
}
else{
qDebug() << "no";
}
QMessageBox::about(this,"关于对话框","fjrktgfiohyh");
}
void MainWindow::on_progresspushButton_6_clicked()
{
QProgressDialog dialog("文件复制进度","取消",0,500000,this);
dialog.setWindowTitle("进度对话框");
dialog.setModal(true);
dialog.show();
for (int i = 0; i < 500000; ++i) {
dialog.setValue(i);
QCoreApplication::processEvents();
if(dialog.wasCanceled())break;
}
dialog.setValue(500000);
qDebug()<<"复制完成";
}
void MainWindow::on_errorpushButton_7_clicked()
{
//为使show this message again有效,需创建对象
errordlg->setWindowTitle("错误信息对话框");
errordlg->showMessage("错误信息");
}
void MainWindow::on_pushButton_8_clicked()
{
QWizard wizard(this);
wizard.setWindowTitle("向导对话框");
wizard.addPage(page1());
wizard.addPage(page2());
wizard.addPage(page3());
wizard.exec();
}
void MainWindow::on_filepushButton_3_clicked()
{
QString str = QFileDialog::getSaveFileName(this,"文件另存为:","D:");
qDebug() << str;
}
QWizardPage *MainWindow::page1()
{
QWizardPage* page = new QWizardPage;
page->setTitle("介绍");
return page;
}
QWizardPage *MainWindow::page2()
{
QWizardPage* page = new QWizardPage;
page->setTitle("用户选择信息");
return page;
}
QWizardPage *MainWindow::page3()
{
QWizardPage* page = new QWizardPage;
page->setTitle("结束");
return page;
}
Qt--->标准对话框
最新推荐文章于 2024-08-17 22:57:57 发布