zoukankan      html  css  js  c++  java
  • Qt之QColorDialog

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

    效果图:

  • 相关阅读:
    synchronized关键字的用法
    for循环删除集合陷阱
    Java之可变参数
    下拉菜单中的Option对象
    JavaScript数组
    线程
    尝试用代码写博客
    环境配置大全
    3中边缘检测算子
    caffe新手入门
  • 原文地址:https://www.cnblogs.com/SunShine-gzw/p/13266835.html
Copyright © 2011-2022 走看看