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();
}

效果图:

最新文章

  1. css的五种属性值----在路上(21)
  2. Windows Server 2012 支持的逻辑盘容量最大是多少?
  3. 后台增加一个左侧列表菜单menu菜单的方法
  4. yii遍历行下的每列数据(小1月考)
  5. 1.html5究竟是什么
  6. PDO应用
  7. iOS开发--验证码
  8. Android 监听ListView、GridView滑动到底部
  9. 【转】linux驱动开发的经典书籍
  10. ImageSpan图片不能居中的问题
  11. C++ 虚函数 、纯虚函数、接口的实用方法和意义
  12. 读Zepto源码之Form模块
  13. Linux 帳號管理與 ACL 權限設定
  14. SQL Server(MySql)中的联合主键(联合索引) 索引分析
  15. Linux垃圾清理
  16. python字符编码和文件处理
  17. Unity 3D光源-Directional平行光/逆光效果,光晕详解、教程
  18. 使用maven创建web项目【转】
  19. django 远程数据库mysql migrate失败报error 1045之 解决方案
  20. Python的collections模块中namedtuple结构使用示例

热门文章

  1. 总结Vue 第四天:vue-cli(Vue2.0 新手入门 — 从环境搭建到发布)
  2. c++之面试(5)
  3. ubuntu下AF_INET和AF_INET6的值
  4. 【LeetCode】857. Minimum Cost to Hire K Workers 解题报告(Python)
  5. 【剑指Offer】合并两个排序的链表 解题报告(Python)
  6. idea使用教程-常用设置
  7. &lt;学习opencv&gt;过滤器和卷积
  8. Java面向对象笔记 • 【第8章 内部类和泛型】
  9. Win10 开启 Hyper-V 及简单使用
  10. SQLAlchemy(十)