内容提要:
了解什么是模态和非模态对话框及实现方法,介绍5中不同类型的对话框使用方法
主要内容:
详细内容:
一个完整的应用程序会经常使用对话框来完成用户与程序的交互操作,所以用好对话框可以提升程序的使用体验,使程序对人更加友好。
1.模态和非模态对话框
1.1 模态对话框
什么是模态对话框?所谓模态对话框,是指如果程序有多个对话框,当模态对话框弹出时,其他的对话框都无法操作,想操作其他对话框,必须先把模态对话框关闭。也就是说模态对话框在没有关闭之前,用户无法与同一个应用程序的其他窗口进行交互操作。
比如我们使用Excel插入一张图片时,弹出的插入图片对话框,在选中图片->点击插入按钮之前,无法操作Excel的其他窗口,这个插入图片窗口就是典型的模态对话框。
怎么使用?在Qt中使用QDialog::exec()函数,把一个对话框变成模态对话框。
QDialog dialog(this);
dialog.exec();
模态对话框练习:
step1 创建一个Qt Widgets 应用,项目名称为mydialog,基类选择Qwidget
step2 可以在widget.cpp添加头文件#include <QDialog>
#include <QDialog>
step3 widget.cpp添加如下代码
QDialog dialog(this);
dialog.exec();
step4 Ctrl+r 运行程序,因为没有设置对话框尺寸,弹出的对话框可能比较小,可以用鼠标拉大对话框
当我们把这个对话框关闭后,会弹出应用程序窗口,由于程序没有添加任何内容,所以是空的。从这个例子可以看出,模态对话框的工作方式,就是在关闭之前,其他的对话框不能执行操作。
1.2 非模态对话框
什么是非模态对话框?所谓非模态对话框,就是在打开它的时候,用户既可以与这个非模态对话框交互,也可以与同一程序的其他窗口交互。
比如使用Excel查找功能,弹出的对话框就是非模态对话框,即使这个对话框弹出来,我们也可以在Excel表内进行其他的操作。
怎么使用?在Qt中使用QDialog::show()来显示非模态对话框
QDialog *dialog = new Qdialog(this);
dialog->show();
非模态对话框练习:
step1 在模态对话练习程序的基础上,注释掉模态对话框的两行代码
// QDialog dialog(this);
// dialog.exec();
step2 添加如下两行代码
QDialog *myDialog = new QDialog(this);
myDialog->show();
step3 Ctrl+r 运行程序,因为没有设置对话框尺寸,弹出的对话框可能比较小,可以用鼠标拉大对话框
对话框与应用程序窗口同时弹出,而且可以操作对话框,也可以是操作应用程序窗口,互相没有影响。
2.标准对话框
为了减少程序设计的工作量,避免不必要的重复代码,Qt提供了一些应用程序开发常用的标准对话框,如颜色对话框,文件对话框,信息提示对话框,输入输出对话框,这样就不需要我们自己再设计这些对话框了,开发应用程序的时候,直接调用这些对话框,提高程序开发的效率。
2.1 颜色对话框
QColorDialog是Qt提供的颜色对话框类,可以用于生成获取指定颜色的的对话框,使用静态函数 QColorDialog::getColor()来获取颜色。
QColorDialog::getColor()函数使用时,需要三个参数,分别是设置初始颜色,指定父窗口,设置对话框标题,函数的返回值是一个颜色变量,如果在颜色对话框里取消选择,则返回的颜色值无效,可以使用QColor::isValid()判断返回值。
颜色对话框的使用练习:预想功能是在窗口上增加一个按钮和标签,点击按钮后,改变标签颜色。
step1 创建一个新项目,Qt Widgets应用,项目名称为dialogTest,基类选择Qwidget(详细创建过程参考前面的文章)
step2 在widget.h中添加头文件
#include <QPushButton>
#include <QLabel>
#include <QColorDialog>
step3 在widget.h中定义按钮和标签,并声明一个槽
private:
QPushButton *button; // 定义按钮
QLabel *label; // 定义标签
private slots:
void editText();
step4 在widget.cpp 文件中写入如下代码,创建按钮和标签
//创建按钮
QPushButton *button = new QPushButton(this);
//设置按钮位置
button->setGeometry(QRect(50,50,80,25));
//设置按钮显示文字
button->setText("change color");
//创建标签
QLabel *label = new QLabel(this);
//label 位置
label->setGeometry(QRect(150,50,200,25));
//label 值
label->setText("the test of text color change");
step5 在widget.cpp 文件中,给按钮绑定editText()这个槽
//给按钮绑定响应事件
connect(button,SIGNAL(clicked()),this,SLOT(editText()));
step6 在widget.cpp 文件中,editText()槽的功能实现
void Widget::editText()
{
//获取当前label的颜色
QPalette pal = label->palette();
QColor initColor = pal.color(QPalette::WindowText);
// 设置颜色对话框
QColor color = QColorDialog::getColor(initColor,this,"select color");
// 判断颜色选择有效性
if (color.isValid()) {
pal.setColor(QPalette::WindowText,QColor(color)); //调色板接收颜色
label->setPalette(pal); //给label 绑定颜色
}
}
step7 Ctrl+r 运行程序,点击按钮,弹出颜色选择对话框,随机选择一个颜色,点击OK后,观察label颜色是否发生变化
2.2 文件对话框
QFileDialog是Qt提供的文件对话框类,用于选择文件或文件夹。要打开一个文件,可调用静态函数 QFileDialog::getOpenFileName(),这个函数产生的对话框是模态对话框,选择文件点击“打开”后,函数会返回选择的文件名。
QFileDialog::getOpenFileName()使用时需要4个参数,分别是:指定父窗口,设置对话框标题,指定默认打开的目录,设置文件类型过滤器,如果不指定文件过滤器,则默认选择所有类型的文件。还可以设置多个过滤器,过滤器之间使用两个分号";;"隔开。
文件对话框的使用练习:预想功能是在窗口上增加一个button和lineEdit,点击按钮后,打开文件选择对话框,选择好文件后,文件名在lineEdit里显示出来
step1 在前面创建的项目dialogTest基础上,widget.h中增加如下代码
#include <QLineEdit>
#include <QFileDialog>
定义按钮和行文本框
private:
QLineEdit *filename;
QPushButton *filebutton;
声明一个槽
private slots:
void showFiles();
step2 在widget.cpp 文件中写入如下代码,创建按钮和行文本框
//创建行文本控件
filename = new QLineEdit(this);
//行文本框的位置
filename->setGeometry(QRect(150,100,200,25));
//创建按钮
filebutton = new QPushButton(this);
//设置按钮位置
filebutton->setGeometry(QRect(50,100,80,25));
//设置按钮显示文字
filebutton->setText("file select");
step3 给按钮绑定showFiles()这个槽
//给按钮绑定响应事件
connect(filebutton,SIGNAL(clicked()),this,SLOT(showFiles()));
step4 showFiles()槽的功能实现
void Widget::showFiles()
{
//定义变量str 接收QFileDialog 对话框获取的文件路径
QString str = QFileDialog::getOpenFileName(this,"open file","/","text file(*.txt);;C file(*.cpp);;All file(*.*)");
//将变量绑定QLineEdit 控件
if (!str.isEmpty()){
filename->setText(str.toUtf8());
}
}
step5 Ctrl+r 运行程序,点击按钮,弹出文件选择对话框,选择一个文件,点击OK后,观察行文本框是否正确显示文件路径
这个练习只能选择单个文件,如果想同时选择多个文件,可以使用getOpenFileNames()函数,另外QFileDialog类还提供了文件保存对话框getSaveFileName()函数,获得已存在文件夹路径函数getExistingDirectory(),使用方法与上面的练习类似。
2.3 字体对话框
QFontDialog 是Qt提供的字体选择对话框,选择字体可以使用静态函数 QFontDialog::getFont(),函数的第一个参数是bool类型的变量,如果为true,则选择字体有效,否则就是没有选择字体。
字体对话框的使用练习:预想功能是在窗口上增加一个button,点击按钮后,打开字体选择对话框,选择好字体后,按钮上文字的字体会发生变化
step1 在前面创建的项目dialogTest基础上,widget.h中增加如下代码
#include <QFontDialog>
声明字体选择按钮
private:
QPushButton *fontbutton;
声明字体选择槽
private slots:
void fontSelect();
step2 在widget.cpp 文件中写入如下代码,创建按钮
//创建按钮
fontbutton = new QPushButton(this);
//设置按钮位置
fontbutton->setGeometry(QRect(50,150,80,25));
//设置按钮显示文字
fontbutton->setText("font change");
step3 在widget.cpp 文件中,给按钮绑定fontSelect()这个槽
//给按钮绑定响应事件
connect(fontbutton,SIGNAL(clicked()),this,SLOT(fontSelect()));
step4 在widget.cpp 文件中,fontSelect()槽的功能实现
void Widget::fontSelect()
{
// ok用于标记是否单击了OK按钮
bool ok = false;
// 获取按钮文字的字体
QFont initFont = fontbutton->font();
// 选择字体
QFont font=QFontDialog::getFont(&ok,initFont);
// 如果点击OK按钮,则文字设置为选择的字体
if (ok) {
fontbutton->setFont(font);
}
}
step5 Ctrl+r 运行程序,点击按钮,弹出字体选择对话框,选择一个字体,点击OK后,观察文字的字体变化
为了对比字体效果,选择了一个很怪异的字体,在字体选择框里还可以设置大小,粗体,斜体等等。
2.4 输入对话框
QInputDialog是Qt提供的标准输入对话框类,可以实现字符串输入,整数输入,浮点数输入,列表框输入等多种输入方式。
4种输入对话框使用练习
step1 在前面创建的项目dialogTest基础上,widget.h中增加如下代码
#include <QInputDialog>
声明按钮
private:
QPushButton *inputStringButton; // 字符串输入按钮
QPushButton *inputIntButton; // 整数输入按钮
QPushButton *inputFloatButton; // 浮点数输入按钮
QPushButton *inputItemButton; // 列表输入按钮
QLineEdit *inputLineEdit; // 输入行文本框
声明槽
private slots:
void inputString(); // 字符串输入
void inputInt(); // 整数输入
void inputFloat(); // 浮点数输入
void inputItem(); // 列表输入
step2 在widget.cpp 文件中写入如下代码,创建按钮和行文本框
// [1]字符串输入按钮
inputStringButton = new QPushButton(this);
//设置按钮位置
inputStringButton->setGeometry(QRect(50,200,80,25));
//设置按钮显示文字
inputStringButton->setText("input string");
// [2]整数输入按钮
inputIntButton = new QPushButton(this);
//设置按钮位置
inputIntButton->setGeometry(QRect(150,200,80,25));
//设置按钮显示文字
inputIntButton->setText("input int");
// [3]浮点数输入按钮
inputFloatButton = new QPushButton(this);
//设置按钮位置
inputFloatButton->setGeometry(QRect(50,250,80,25));
//设置按钮显示文字
inputFloatButton->setText("input float");
// [4]列表输入按钮
inputItemButton = new QPushButton(this);
//设置按钮位置
inputItemButton->setGeometry(QRect(150,250,80,25));
//设置按钮显示文字
inputItemButton->setText("input item");
// 输入行文本框
inputLineEdit = new QLineEdit(this);
//行文本框的位置
inputLineEdit->setGeometry(QRect(50,300,180,25));
step3 在widget.cpp 文件中,给按钮绑定槽
//给按钮绑定响应事件
connect(inputStringButton,SIGNAL(clicked()),this,SLOT(inputString()));
connect(inputIntButton,SIGNAL(clicked()),this,SLOT(inputInt()));
connect(inputFloatButton,SIGNAL(clicked()),this,SLOT(inputFloat()));
connect(inputItemButton,SIGNAL(clicked()),this,SLOT(inputItem()));
step4 在widget.cpp 文件中,按钮槽的功能实现
// [1]字符串输入
void Widget::inputString(){
bool ok=false;
QString string = QInputDialog::getText(this,"input string dialog",
"please input file name",QLineEdit::Normal,"admin",&ok);
if (ok && !string.isEmpty()){
inputLineEdit->setText(string);
}
}
// [2]整数输入
void Widget::inputInt(){
bool ok=false;
int intValue = QInputDialog::getInt(this,"input int dialog","please input a number of -100~100 ",
100,-100,100,10,&ok);
if (ok){
inputLineEdit->setText(QString::number(intValue)); // 整型数据转换成字符串显示
}
}
// [3]浮点数输入
void Widget::inputFloat(){
bool ok=false;
float floatValue = QInputDialog::getDouble(this,"inpt float dialog","input a number of -100~100",
0.00,-100,100,2,&ok);
if (ok){
inputLineEdit->setText(QString::number(floatValue));
}
}
// [4]列表输入
void Widget::inputItem(){
// 定义项目列表
QStringList items;
items <<"item1" <<"item2" <<"item3";
bool ok=false;
QString item = QInputDialog::getItem(this,"input item dialog","please select a item",
items,0,true,&ok);
if (ok && !item.isEmpty()){
inputLineEdit->setText(item);
}
}
step5 Ctrl+r 运行程序,点击按钮,看看能否正常输入信息
2.5 消息对话框
QMessageBox是Qt提供的模态消息对话框类,提供消息,警告,错误等信息给用户,提高用户使用程序的体验,更加友好
消息对话框使用练习:设置4个按钮,当点击按钮后,弹出一种消息对话框
step1 在前面创建的项目dialogTest基础上,widget.h中增加如下代码
#include <QMessageBox>
声明按钮
private:
QPushButton *informationButton; // 提示按钮
QPushButton *warningButton; // 警告按钮
QPushButton *critiButton; // 错误按钮
QPushButton *aboutButton; // 关于按钮
声明槽
private slots:
void informationMessage(); // 消息提示
void warningMessage(); // 警告信息
void ctrticalMessage(); // 错误信息
void aboutMessage(); // 关于信息
step2 在widget.cpp 文件中写入如下代码,创建按钮
// [5]字符串输入按钮
informationButton = new QPushButton(this);
//设置按钮位置
informationButton->setGeometry(QRect(280,200,80,25));
//设置按钮显示文字
informationButton->setText("information");
// [6]整数输入按钮
warningButton = new QPushButton(this);
//设置按钮位置
warningButton->setGeometry(QRect(380,200,80,25));
//设置按钮显示文字
warningButton->setText("warning");
// [7]浮点数输入按钮
criticalButton = new QPushButton(this);
//设置按钮位置
criticalButton->setGeometry(QRect(280,250,80,25));
//设置按钮显示文字
criticalButton->setText("critical");
// [8]列表输入按钮
aboutButton = new QPushButton(this);
//设置按钮位置
aboutButton->setGeometry(QRect(380,250,80,25));
//设置按钮显示文字
aboutButton->setText("about");
step3 给按钮绑定槽
//给按钮绑定响应事件
connect(informationButton,SIGNAL(clicked()),this,SLOT(informationMessage()));
connect(warningButton,SIGNAL(clicked()),this,SLOT(warningMessage()));
connect(criticalButton,SIGNAL(clicked()),this,SLOT(ctrticalMessage()));
connect(aboutButton,SIGNAL(clicked()),this,SLOT(aboutMessage()));
step4 按钮槽的功能实现
// [5]消息提示
void Widget::informationMessage(){
QMessageBox::information(this, "information message box", "this is a test program",
QMessageBox::Ok,QMessageBox::NoButton);
}
// [6]警告信息
void Widget::warningMessage(){
QMessageBox::warning(this, "warning message box", "this is a test program");
}
// [7]错误信息
void Widget::ctrticalMessage(){
QMessageBox::critical(this, "critical message box", "this is a test program");
}
// [8]关于信息
void Widget::aboutMessage(){
QMessageBox::about(this, "about message box", "this is a Qt program");
}
step5 Ctrl+r 运行程序,点击按钮,看看能否正常弹出消息对话框
以上就是关于模态与非模态对话框,常用标准对话框的内容,虽然内容有点多,但在开发程序中,使用比较多,所以建议看一遍之后,多多练习,写程序多调试几次,熟练掌握最好。
添附:
模态和非模态对话框源码,只修改widget.cpp文件内容,其他地方没有改动
mydialog项目:widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include <QDialog>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
QDialog *myDialog = new QDialog(this);
myDialog->show();
// QDialog dialog(this);
// dialog.exec();
}
Widget::~Widget()
{
delete ui;
}
dialogTest项目:widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QColorDialog>
#include <QLineEdit>
#include <QFileDialog>
#include <QFontDialog>
#include <QInputDialog>
#include <QMessageBox>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private:
Ui::Widget *ui;
QPushButton *button; // 定义按钮
QLabel *label; // 定义标签
QLineEdit *filename; // 行文本框
QPushButton *filebutton; // 文件选择按钮
QPushButton *fontbutton; // 字体选择按钮
QPushButton *inputStringButton; // 字符串输入按钮
QPushButton *inputIntButton; // 整数输入按钮
QPushButton *inputFloatButton; // 浮点数输入按钮
QPushButton *inputItemButton; // 列表输入按钮
QLineEdit *inputLineEdit; // 输入行文本框
QPushButton *informationButton; // 消息提示按钮
QPushButton *warningButton; // 警告信息按钮
QPushButton *criticalButton; // 错误信息按钮
QPushButton *aboutButton; // 关于信息按钮
private slots:
void informationMessage(); // 消息提示
void warningMessage(); // 警告信息
void ctrticalMessage(); // 错误信息
void aboutMessage(); // 关于信息
void inputString(); // 字符串输入
void inputInt(); // 整数输入
void inputFloat(); // 浮点数输入
void inputItem(); // 列表输入
void fontSelect(); // 字体选择
void showFiles(); // 文件选择
void editText(); // 文字颜色选择
};
#endif // WIDGET_H
dialogTest项目:widget.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//创建颜色选择按钮
button = new QPushButton(this);
//设置按钮位置
button->setGeometry(QRect(50,50,80,25));
//设置按钮显示文字
button->setText("change color");
//创建标签
label = new QLabel(this);
//label 位置
label->setGeometry(QRect(150,50,200,25));
//label 值
label->setText("the test of text color change");
//给按钮绑定响应事件
connect(button,SIGNAL(clicked()),this,SLOT(editText()));
//创建行文本控件
filename = new QLineEdit(this);
//行文本框的位置
filename->setGeometry(QRect(150,100,200,25));
//创建按钮
filebutton = new QPushButton(this);
//设置按钮位置
filebutton->setGeometry(QRect(50,100,80,25));
//设置按钮显示文字
filebutton->setText("file select");
//给按钮绑定响应事件
connect(filebutton,SIGNAL(clicked()),this,SLOT(showFiles()));
//创建字体选按钮
fontbutton = new QPushButton(this);
//设置按钮位置
fontbutton->setGeometry(QRect(50,150,80,25));
//设置按钮显示文字
fontbutton->setText("font change");
//给按钮绑定响应事件
connect(fontbutton,SIGNAL(clicked()),this,SLOT(fontSelect()));
// [1]字符串输入按钮
inputStringButton = new QPushButton(this);
//设置按钮位置
inputStringButton->setGeometry(QRect(50,200,80,25));
//设置按钮显示文字
inputStringButton->setText("input string");
// [2]整数输入按钮
inputIntButton = new QPushButton(this);
//设置按钮位置
inputIntButton->setGeometry(QRect(150,200,80,25));
//设置按钮显示文字
inputIntButton->setText("input int");
// [3]浮点数输入按钮
inputFloatButton = new QPushButton(this);
//设置按钮位置
inputFloatButton->setGeometry(QRect(50,250,80,25));
//设置按钮显示文字
inputFloatButton->setText("input float");
// [4]列表输入按钮
inputItemButton = new QPushButton(this);
//设置按钮位置
inputItemButton->setGeometry(QRect(150,250,80,25));
//设置按钮显示文字
inputItemButton->setText("input item");
// 输入行文本框
inputLineEdit = new QLineEdit(this);
//行文本框的位置
inputLineEdit->setGeometry(QRect(50,300,180,25));
//给按钮绑定响应事件
connect(inputStringButton,SIGNAL(clicked()),this,SLOT(inputString()));
connect(inputIntButton,SIGNAL(clicked()),this,SLOT(inputInt()));
connect(inputFloatButton,SIGNAL(clicked()),this,SLOT(inputFloat()));
connect(inputItemButton,SIGNAL(clicked()),this,SLOT(inputItem()));
// [5]消息提示按钮
informationButton = new QPushButton(this);
//设置按钮位置
informationButton->setGeometry(QRect(280,200,80,25));
//设置按钮显示文字
informationButton->setText("information");
// [6]警告信息按钮
warningButton = new QPushButton(this);
//设置按钮位置
warningButton->setGeometry(QRect(380,200,80,25));
//设置按钮显示文字
warningButton->setText("warning");
// [7]错误信息按钮
criticalButton = new QPushButton(this);
//设置按钮位置
criticalButton->setGeometry(QRect(280,250,80,25));
//设置按钮显示文字
criticalButton->setText("critical");
// [8]关于信息按钮
aboutButton = new QPushButton(this);
//设置按钮位置
aboutButton->setGeometry(QRect(380,250,80,25));
//设置按钮显示文字
aboutButton->setText("about");
//给按钮绑定响应事件
connect(informationButton,SIGNAL(clicked()),this,SLOT(informationMessage()));
connect(warningButton,SIGNAL(clicked()),this,SLOT(warningMessage()));
connect(criticalButton,SIGNAL(clicked()),this,SLOT(ctrticalMessage()));
connect(aboutButton,SIGNAL(clicked()),this,SLOT(aboutMessage()));
}
// [5]消息提示
void Widget::informationMessage(){
QMessageBox::information(this, "information message box", "this is a test program",
QMessageBox::Ok,QMessageBox::NoButton);
}
// [6]警告信息
void Widget::warningMessage(){
QMessageBox::warning(this, "warning message box", "this is a test program");
}
// [7]错误信息
void Widget::ctrticalMessage(){
QMessageBox::critical(this, "critical message box", "this is a test program");
}
// [8]关于信息
void Widget::aboutMessage(){
QMessageBox::about(this, "about message box", "this is a Qt program");
}
// [1]字符串输入
void Widget::inputString(){
bool ok=false;
QString string = QInputDialog::getText(this,"input string dialog",
"please input file name",QLineEdit::Normal,"admin",&ok);
if (ok && !string.isEmpty()){
inputLineEdit->setText(string);
}
}
// [2]整数输入
void Widget::inputInt(){
bool ok=false;
int intValue = QInputDialog::getInt(this,"input int dialog","please input a number of -100~100 ",
100,-100,100,10,&ok);
if (ok){
inputLineEdit->setText(QString::number(intValue)); // 整型数据转换成字符串显示
}
}
// [3]浮点数输入
void Widget::inputFloat(){
bool ok=false;
float floatValue = QInputDialog::getDouble(this,"inpt float dialog","input a number of -100~100",
0.00,-100,100,2,&ok);
if (ok){
inputLineEdit->setText(QString::number(floatValue));
}
}
// [4]列表输入
void Widget::inputItem(){
// 定义项目列表
QStringList items;
items <<"item1" <<"item2" <<"item3";
bool ok=false;
QString item = QInputDialog::getItem(this,"input item dialog","please select a item",
items,0,true,&ok);
if (ok && !item.isEmpty()){
inputLineEdit->setText(item);
}
}
void Widget::fontSelect()
{
// ok用于标记是否单击了OK按钮
bool ok = false;
// 获取按钮文字的字体
QFont initFont = fontbutton->font();
// 选择字体
QFont font=QFontDialog::getFont(&ok,initFont);
// 如果点击OK按钮,则文字设置为选择的字体
if (ok) {
fontbutton->setFont(font);
}
}
void Widget::showFiles()
{
//定义变量str 接收QFileDialog 对话框获取的文件路径
QString str = QFileDialog::getOpenFileName(this,"open file","/","text file(*.txt);;C file(*.cpp);;All file(*.*)");
//将变量绑定QLineEdit 控件
if (!str.isEmpty()){
filename->setText(str.toUtf8());
}
}
void Widget::editText()
{
//获取当前label的颜色
QPalette pal = label->palette();
QColor initColor = pal.color(QPalette::WindowText);
// 设置颜色对话框
QColor color = QColorDialog::getColor(initColor,this,"select color");
// 判断颜色选择有效性
if (color.isValid()) {
pal.setColor(QPalette::WindowText,QColor(color)); //调色板接收颜色
label->setPalette(pal); //给label 绑定颜色
}
}
Widget::~Widget()
{
delete ui;
}