70 lines
2.1 KiB
C++
70 lines
2.1 KiB
C++
|
#include "widget.h"
|
||
|
#include "ui_widget.h"
|
||
|
#include <QColorDialog>
|
||
|
#include <QDebug>
|
||
|
#include <QDialog>
|
||
|
#include <QFileDialog>
|
||
|
#include <QFontDialog>
|
||
|
#include <QInputDialog>
|
||
|
#include <QMessageBox>
|
||
|
#include <QProgressDialog>
|
||
|
|
||
|
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) {
|
||
|
ui->setupUi(this);
|
||
|
}
|
||
|
|
||
|
Widget::~Widget() { delete ui; }
|
||
|
|
||
|
void Widget::on_pushButton_clicked() {
|
||
|
QColorDialog dialog(Qt::red, this);
|
||
|
dialog.setOption(QColorDialog::ShowAlphaChannel);
|
||
|
dialog.exec();
|
||
|
QColor color = dialog.currentColor();
|
||
|
qDebug() << "color:" << color;
|
||
|
}
|
||
|
|
||
|
void Widget::on_pushButton_5_clicked() {
|
||
|
QString fileName = QFileDialog::getOpenFileName(
|
||
|
this, "文件对话框", "D:", "图片文件(* png * jpg);;文本文件(*txt)");
|
||
|
qDebug() << "fileName:" << fileName;
|
||
|
}
|
||
|
|
||
|
void Widget::on_pushButton_2_clicked() {
|
||
|
bool ok = false;
|
||
|
QFont font = QFontDialog::getFont(&ok, this);
|
||
|
if (ok) {
|
||
|
ui->pushButton_2->setFont(font);
|
||
|
} else {
|
||
|
qDebug() << "没有选择字体";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Widget::on_pushButton_6_clicked() {
|
||
|
bool ok;
|
||
|
QString name = QInputDialog::getText(this, "输入对话框", "请输入用户名:",
|
||
|
QLineEdit::Normal, "admin", &ok);
|
||
|
if (ok) {
|
||
|
qDebug() << "name:" << name;
|
||
|
}
|
||
|
int intNum = QInputDialog::getInt(this, "整数输入对话框",
|
||
|
"请输入-1000到1000之间的数值", 100, -1000,
|
||
|
1000, 10, &ok);
|
||
|
if (ok) {
|
||
|
qDebug() << "intNum:" << intNum;
|
||
|
}
|
||
|
double doubleNum = QInputDialog::getDouble(this, "浮点数输入对话框",
|
||
|
"请输入-1000到1000的数值", 0.00,
|
||
|
-1000, 1000, 2, &ok);
|
||
|
if (ok) {
|
||
|
qDebug() << "doubleNum:" << doubleNum;
|
||
|
}
|
||
|
QStringList items;
|
||
|
items << "条目1"
|
||
|
<< "条目2";
|
||
|
QString item = QInputDialog::getItem(
|
||
|
this, "条目输入对话框", "请选择或输入一个条目", items, 0, true, &ok);
|
||
|
if (ok) {
|
||
|
qDebug() << "item:" << item;
|
||
|
}
|
||
|
}
|