Qt之QColorDialog
2024-08-27 16:23:41
widget.h:
#ifndef WIDGET_H
#define WIDGET_H #include <QWidget> class Widget : public QWidget
{
Q_OBJECT public:
Widget(QWidget *parent = 0);
~Widget();
public slots:
void showColor();
}; #endif // WIDGET_H
widget.cpp:
#include "widget.h"
#include<QColor>
#include<QColorDialog>
#include<QPushButton>
#include<QPalette> //调色板
#include<QLabel>
#include<QHBoxLayout>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
this->resize(600,480);
QPalette qpalette=this->palette();
QHBoxLayout *s=new QHBoxLayout(this);
qpalette.color( QPalette::WindowText);
qpalette.setColor(QPalette::WindowText,QColor(255,0,0));
qpalette.setColor(QPalette::Background,QColor("#0f8Fb0"));
this->setPalette(qpalette);
QPushButton *qp=new QPushButton("打开",this);
QLabel* ql=new QLabel("打开",this);
s->addWidget(qp);
s->addWidget(ql);
connect(qp,SIGNAL(clicked()),this,SLOT(showColor()));
}
void Widget::showColor()
{
QColor qc=QColorDialog::getColor(QColor("#0023ff"),this,"dfsd");
if(qc.isValid())
{
QPalette temp=this->palette();
temp.setColor(QPalette::Background,qc);
this->setPalette(temp);
}
}
Widget::~Widget()
{ }
main.cpp:
#include "widget.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show(); return a.exec();
}
效果图:
最新文章
- css的五种属性值----在路上(21)
- Windows Server 2012 支持的逻辑盘容量最大是多少?
- 后台增加一个左侧列表菜单menu菜单的方法
- yii遍历行下的每列数据(小1月考)
- 1.html5究竟是什么
- PDO应用
- iOS开发--验证码
- Android 监听ListView、GridView滑动到底部
- 【转】linux驱动开发的经典书籍
- ImageSpan图片不能居中的问题
- C++ 虚函数 、纯虚函数、接口的实用方法和意义
- 读Zepto源码之Form模块
- Linux 帳號管理與 ACL 權限設定
- SQL Server(MySql)中的联合主键(联合索引) 索引分析
- Linux垃圾清理
- python字符编码和文件处理
- Unity 3D光源-Directional平行光/逆光效果,光晕详解、教程
- 使用maven创建web项目【转】
- django 远程数据库mysql migrate失败报error 1045之 解决方案
- Python的collections模块中namedtuple结构使用示例
热门文章
- 总结Vue 第四天:vue-cli(Vue2.0 新手入门 — 从环境搭建到发布)
- c++之面试(5)
- ubuntu下AF_INET和AF_INET6的值
- 【LeetCode】857. Minimum Cost to Hire K Workers 解题报告(Python)
- 【剑指Offer】合并两个排序的链表 解题报告(Python)
- idea使用教程-常用设置
- <;学习opencv>;过滤器和卷积
- Java面向对象笔记 • 【第8章 内部类和泛型】
- Win10 开启 Hyper-V 及简单使用
- SQLAlchemy(十)