mirror of
https://gitee.com/drabel/LibQQt.git
synced 2025-01-04 10:18:44 +08:00
add colorwidgettest
This commit is contained in:
parent
cd9383731c
commit
71b454f700
@ -9,6 +9,7 @@
|
||||
TEMPLATE = subdirs
|
||||
CONFIG += ordered
|
||||
|
||||
SUBDIRS += test/colorwidgettest
|
||||
#SUBDIRS += demo/QQtClientCreator
|
||||
#SUBDIRS += demo/QQtServerCreator
|
||||
#SUBDIRS += demo/QQtRoseMonitor
|
||||
|
@ -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() );
|
||||
}
|
||||
|
@ -22,6 +22,10 @@ signals:
|
||||
public slots:
|
||||
private:
|
||||
QRgb mRgb;
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
virtual void paintEvent ( QPaintEvent* event ) override;
|
||||
};
|
||||
|
||||
#endif // QQTCOLORWIDGET_H
|
||||
|
42
test/colorwidgettest/colorwidgettest.pro
Normal file
42
test/colorwidgettest/colorwidgettest.pro
Normal file
@ -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)
|
11
test/colorwidgettest/main.cpp
Normal file
11
test/colorwidgettest/main.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QQtApplication>
|
||||
|
||||
int main ( int argc, char* argv[] )
|
||||
{
|
||||
QQtApplication a ( argc, argv );
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
24
test/colorwidgettest/mainwindow.cpp
Normal file
24
test/colorwidgettest/mainwindow.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <qqtcolorwidget.h>
|
||||
|
||||
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();
|
||||
}
|
25
test/colorwidgettest/mainwindow.h
Normal file
25
test/colorwidgettest/mainwindow.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
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
|
45
test/colorwidgettest/mainwindow.ui
Normal file
45
test/colorwidgettest/mainwindow.ui
Normal file
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>520</width>
|
||||
<height>329</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>change</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QQtColorWidget" name="widget" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QQtColorWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qqtcolorwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
x
Reference in New Issue
Block a user