diff --git a/QQtExample_Temp.pro b/QQtExample_Temp.pro index 65e2f3b8..c3ac976e 100644 --- a/QQtExample_Temp.pro +++ b/QQtExample_Temp.pro @@ -9,6 +9,7 @@ TEMPLATE = subdirs CONFIG += ordered +SUBDIRS += test/colorwidgettest #SUBDIRS += demo/QQtClientCreator #SUBDIRS += demo/QQtServerCreator #SUBDIRS += demo/QQtRoseMonitor diff --git a/src/exquisite/colorwidgets/qqtcolorwidget.cpp b/src/exquisite/colorwidgets/qqtcolorwidget.cpp index 6234406e..b8bf93d3 100644 --- a/src/exquisite/colorwidgets/qqtcolorwidget.cpp +++ b/src/exquisite/colorwidgets/qqtcolorwidget.cpp @@ -2,20 +2,25 @@ QQtColorWidget::QQtColorWidget ( QWidget* parent ) : QWidget ( parent ) { - setStyleSheet ( "QWidget{background-color:#FFFFFF;}" ); } void QQtColorWidget::setColor ( const QRgb& rgb ) { mRgb = rgb; - QString colorString = QString ( "QWidget{background-color:#%1%2%3;}" ) - .arg ( qRed ( rgb ), 2, 16, QChar ( '0' ) ) - .arg ( qGreen ( rgb ), 2, 16, QChar ( '0' ) ) - .arg ( qBlue ( rgb ), 2, 16, QChar ( '0' ) ); - setStyleSheet ( colorString ); } QRgb QQtColorWidget::getColor() { return mRgb; } + + +void QQtColorWidget::paintEvent ( QPaintEvent* event ) +{ + QPainter painter ( this ); + //QPen pen = painter.pen(); + //pen.setColor ( QColor ( mRgb ) ); + painter.setPen ( Qt::NoPen ); + painter.setBrush ( QBrush ( QColor ( mRgb ) ) ); + painter.drawRect ( rect() ); +} diff --git a/src/exquisite/colorwidgets/qqtcolorwidget.h b/src/exquisite/colorwidgets/qqtcolorwidget.h index 4a7def68..5a3caa22 100644 --- a/src/exquisite/colorwidgets/qqtcolorwidget.h +++ b/src/exquisite/colorwidgets/qqtcolorwidget.h @@ -22,6 +22,10 @@ signals: public slots: private: QRgb mRgb; + + // QWidget interface +protected: + virtual void paintEvent ( QPaintEvent* event ) override; }; #endif // QQTCOLORWIDGET_H diff --git a/test/colorwidgettest/colorwidgettest.pro b/test/colorwidgettest/colorwidgettest.pro new file mode 100644 index 00000000..83e12d75 --- /dev/null +++ b/test/colorwidgettest/colorwidgettest.pro @@ -0,0 +1,42 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2018-07-23T15:24:35 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = colorwidgettest +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + + +SOURCES += \ + main.cpp \ + mainwindow.cpp + +HEADERS += \ + mainwindow.h + +FORMS += \ + mainwindow.ui + +CONFIG += mobility +MOBILITY = + +include (../../multi-link/add_base_manager.pri) +add_version(1,0,0,0) +add_deploy() +add_dependent_manager(QQt) diff --git a/test/colorwidgettest/main.cpp b/test/colorwidgettest/main.cpp new file mode 100644 index 00000000..219ca126 --- /dev/null +++ b/test/colorwidgettest/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main ( int argc, char* argv[] ) +{ + QQtApplication a ( argc, argv ); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/test/colorwidgettest/mainwindow.cpp b/test/colorwidgettest/mainwindow.cpp new file mode 100644 index 00000000..8bf1bb5f --- /dev/null +++ b/test/colorwidgettest/mainwindow.cpp @@ -0,0 +1,24 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include + +MainWindow::MainWindow ( QWidget* parent ) : + QMainWindow ( parent ), + ui ( new Ui::MainWindow ) +{ + ui->setupUi ( this ); + ui->lineEdit->setText ( "0x863356" ); + ui->widget->setColor ( QRgb ( ui->lineEdit->text().toInt() ) ); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_pushButton_clicked() +{ + ui->widget->setColor ( QRgb ( ui->lineEdit->text().toInt() ) ); + ui->widget->setAutoFillBackground ( true ); + ui->widget->update(); +} diff --git a/test/colorwidgettest/mainwindow.h b/test/colorwidgettest/mainwindow.h new file mode 100644 index 00000000..365e5ae0 --- /dev/null +++ b/test/colorwidgettest/mainwindow.h @@ -0,0 +1,25 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow ( QWidget* parent = 0 ); + ~MainWindow(); + +private slots: + void on_pushButton_clicked(); + +private: + Ui::MainWindow* ui; +}; + +#endif // MAINWINDOW_H diff --git a/test/colorwidgettest/mainwindow.ui b/test/colorwidgettest/mainwindow.ui new file mode 100644 index 00000000..6399c4ac --- /dev/null +++ b/test/colorwidgettest/mainwindow.ui @@ -0,0 +1,45 @@ + + + MainWindow + + + + 0 + 0 + 520 + 329 + + + + MainWindow + + + + + + + + + + change + + + + + + + + + + + + + QQtColorWidget + QWidget +
qqtcolorwidget.h
+ 1 +
+
+ + +