#include<QDebug>
#include<QColorDialog>//颜色对话框
#include<QFileDialog> //文件对话框
#include<QFontDialog> //字体对话框
#include<QInputDialog>//输入对话框
/* 颜色对话框 */
void
MyWidget::on_pushButton_clicked()
{
// 创建对象
QColorDialog dialog(Qt::red,
this
);
// 显示 alpha 选项
dialog.setOption(QColorDialog::ShowAlphaChannel);
// 以模态方式运行对话框
dialog.exec();
// 获取当前颜色
QColor color = dialog.currentColor();
// 输出颜色信息
qDebug()<<
"color:"
<<color;
}
/* 文件对话框 */
void
MyWidget::on_pushButton_5_clicked()
{
// 选择单个文件
//QString fileName = QFileDialog::getOpenFileName(this,tr("文件对话框"),"D:",tr("图片文件(*png *jpg);;文本文件(*txt)"));
// 选择多个文件
QStringList fileName = QFileDialog::getOpenFileNames(
this
,tr(
"文件对话框"
),
"D:"
,tr(
"图片文件(*png *jpg);;文本文件(*txt)"
));
qDebug()<<
"fileName"
<<fileName;
}
/* 字体对话框 */
void
MyWidget::on_pushButton_2_clicked()
{
// ok用于标记是否单击了 OK按钮
bool
ok;
// 选择字体
QFont font = QFontDialog::getFont(&ok,
this
);
// 如果单击了 OK按钮 , 那么让 "字体对话框" 使用新字体
// 如果单击 cancel 按钮 那么输出信息
if
(ok)
{
// 设置按钮显示字体
ui->pushButton_2->setFont(font);
qDebug()<<tr(
"选择字体:"
)<<font;
}
else
{
qDebug()<<tr(
"没有选择字体"
);
}
}
/* 输入对话框 */
void
MyWidget::on_pushButton_6_clicked()
{
bool
ok;
// 获取字符串
QString string = QInputDialog::getText(
this
,tr(
"请输入字符串对话框"
),
tr(
"请输入用户名:"
),QLineEdit::Normal,tr(
"admin"
),&ok);
if
(ok) {qDebug()<<
"string:"
<<string;}
// 获取整数
int
value1 = QInputDialog::getInt(
this
, tr(
"输入整数对话框"
),
tr(
"请输入-1000到1000之间的数值"
), 100, -1000, 1000, 10, &ok);
if
(ok) {qDebug()<<
"value1:"
<<value1;}
// 获取浮点数
double
value2 = QInputDialog::getDouble(
this
, tr(
"输入浮点数对话框"
),
tr(
"请输入-1000到1000的数值"
), 0.00, -1000, 1000, 2, &ok);
if
(ok) {qDebug()<<
"value2:"
<<value2;}
// 获取条目
QStringList items;
items << tr(
"条目1"
) << tr(
"条目2"
) << tr(
"条目3"
) << tr(
"条目4"
);
QString item = QInputDialog::getItem(
this
, tr(
"输入条目对话框"
),
tr(
"请选择或输入一个条目"
), items, 0,
true
, &ok);
if
(ok) {qDebug()<<
"item:"
<<item;}
}
/* 消息对话框 */
void
MyWidget::on_pushButton_3_clicked()
{
//未完持续
}