Qt标准对话框之QColorDialog
2017-05-20 23:43
253 查看
在mainwindow.h MainWindow类中添加
构造函数
colorDlg的两种写法:
第一种:
第二种:
public slots: void colorDlg();
构造函数
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { resize(600,600); QPushButton *pb1 = new QPushButton("颜色",this); pb1->move(150,50); connect(pb1,&QPushButton::clicked,this,MainWindow::colorDlg); }
colorDlg的两种写法:
第一种:
void MainWindow::colorDlg() { //增加QColorDialog::ShowAlphaChannel 可设置透明度 QColor color = QColorDialog::getColor(Qt::red,this,tr("颜色对话框"),QColorDialog::ShowAlphaChannel); //若点击了对话框的取消则得到非法颜色 if(color.isValid()) { //将得到的颜色作为窗口背景色 QPalette qp(this->palette()); qp.setColor(QPalette::Background,color); this->setAutoFillBackground(true); this->setPalette(qp); } }
第二种:
void MainWindow::colorDlg() { //通过建立QColorDialog比较灵活 QColorDialog cd; cd.setOption(QColorDialog::ShowAlphaChannel); cd.exec(); QColor color = cd.currentColor(); if(color.isValid()) { QPalette qp(this->palette()); qp.setColor(QPalette::Background,color); this->setAutoFillBackground(true); this->setPalette(qp); } }
相关文章推荐
- Qt学习之路(16): Qt标准对话框之QColorDialog
- Qt学习之路(16): Qt标准对话框之QColorDialog
- Qt标准对话框之 QColorDialog-16
- Qt标准对话框之QFileDialog
- Qt学习之路(18): Qt标准对话框之QInputDialog
- Qt标准对话框之QFileDialog
- Qt标准对话框之QMessageBox
- Qt标准对话框之消息对话框(QMessageBox)
- Qt学习之路(16): Qt标准对话框之QColorDialog
- Qt之对话框设计——(1)标准对话框
- Qt学习之路(17): Qt标准对话框之QMessageBox
- 自学QT之标准文件对话框
- Qt浅谈之三:内置标准对话框
- qt 标准对话框
- Qt学习之路(18): Qt标准对话框之QInputDialog
- Qt学习之路(15): Qt标准对话框之QFileDialog
- QT学习 之 对话框 (三) 标准颜色对话框
- 【Qt开发】Qt标准对话框之QMessageBox
- QT之标准对话框
- Qt学习之路(15): Qt标准对话框之QFileDialog