QColorDialog类
Qt中提供标准对话框,其中QColorDialog类(颜色对话框)。备注:不同系统平台显示效果有所不同,(原因是系统主题风格不一样,但功能一样)。
#ifndef DIALOG_H #define DIALOG_H #include <QDialog> #include <QPushButton> #include <QFrame> #include <QColor> #include <QGridLayout> class Dialog : public QDialog { Q_OBJECT public: Dialog(QWidget *parent = 0); ~Dialog(); private: QGridLayout *glayout; QPushButton *colorbutton; //基本控件的基类 QFrame *colorFrame; private slots: void dispcolorFunc(); }; #endif // DIALOG_H
#include "dialog.h" #include <QColorDialog> Dialog::Dialog(QWidget *parent) : QDialog(parent) { setWindowTitle("颜色对话测试筐"); glayout=new QGridLayout(this); colorbutton=new QPushButton("打开颜色选择"); colorFrame=new QFrame; colorFrame->setFrameShape(QFrame::Box);//设置形状 colorFrame->setAutoFillBackground(true);//填充背景处理 glayout->addWidget(colorbutton,0,0); glayout->addWidget(colorFrame,1,0); //信号槽函数的连接 connect(colorbutton,SIGNAL(clicked()),this,SLOT(dispcolorFunc())); } Dialog::~Dialog() { } void Dialog::dispcolorFunc() { QColor colorValues= QColorDialog::getColor(Qt::red); if(colorValues.isValid()){ colorFrame->setPalette(QPalette(colorValues)); } }
标签:颜色,colorbutton,对话框,QColorDialog,Dialog,include,colorFrame From: https://www.cnblogs.com/baisedeyu/p/17882190.html