From 29359f64b67f75681f04f0c45f5608451848a94a Mon Sep 17 00:00:00 2001 From: muli Date: Fri, 14 Feb 2020 00:09:27 +0800 Subject: [PATCH] feat: Display several styles of the operating system through QStyleFactory --- .../QtExample01/QtStyleEx/QtStyleEx.pro | 37 +++++++++++ QtMyStyleEx/QtExample01/QtStyleEx/main.cpp | 11 ++++ QtMyStyleEx/QtExample01/QtStyleEx/widget.cpp | 65 +++++++++++++++++++ QtMyStyleEx/QtExample01/QtStyleEx/widget.h | 17 +++++ 4 files changed, 130 insertions(+) create mode 100644 QtMyStyleEx/QtExample01/QtStyleEx/QtStyleEx.pro create mode 100644 QtMyStyleEx/QtExample01/QtStyleEx/main.cpp create mode 100644 QtMyStyleEx/QtExample01/QtStyleEx/widget.cpp create mode 100644 QtMyStyleEx/QtExample01/QtStyleEx/widget.h diff --git a/QtMyStyleEx/QtExample01/QtStyleEx/QtStyleEx.pro b/QtMyStyleEx/QtExample01/QtStyleEx/QtStyleEx.pro new file mode 100644 index 0000000..53224c6 --- /dev/null +++ b/QtMyStyleEx/QtExample01/QtStyleEx/QtStyleEx.pro @@ -0,0 +1,37 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2020-02-13T22:45:19 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = QtStyleEx +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 + +CONFIG += c++11 + +SOURCES += \ + main.cpp \ + widget.cpp + +HEADERS += \ + widget.h + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/QtMyStyleEx/QtExample01/QtStyleEx/main.cpp b/QtMyStyleEx/QtExample01/QtStyleEx/main.cpp new file mode 100644 index 0000000..90b6d53 --- /dev/null +++ b/QtMyStyleEx/QtExample01/QtStyleEx/main.cpp @@ -0,0 +1,11 @@ +#include "widget.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + + return a.exec(); +} diff --git a/QtMyStyleEx/QtExample01/QtStyleEx/widget.cpp b/QtMyStyleEx/QtExample01/QtStyleEx/widget.cpp new file mode 100644 index 0000000..d486e8e --- /dev/null +++ b/QtMyStyleEx/QtExample01/QtStyleEx/widget.cpp @@ -0,0 +1,65 @@ +#include "widget.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +Widget::Widget(QWidget *parent) + : QWidget(parent) +{ + init(); +} + +Widget::~Widget() +{ + +} + +void Widget::init() +{ + QTableWidget *table = new QTableWidget(10, 10, this); + table->move(10, 10); + + QScrollBar *scrollBarH = new QScrollBar(this); + scrollBarH->move(300, 50); + scrollBarH->setRange(0, 100); + scrollBarH->setValue(34); + scrollBarH->resize(380, 20); + scrollBarH->setOrientation(Qt::Horizontal); + + QScrollBar *scrollBarV = new QScrollBar(this); + scrollBarV->move(50, 250); + scrollBarV->setRange(0, 100); + scrollBarV->setValue(67); + scrollBarV->resize(20, 380); + scrollBarV->setOrientation(Qt::Vertical); + + QProgressBar* progreH = new QProgressBar(this); + progreH->move(300, 100); + progreH->resize(250, 40); + progreH->setValue(37); + progreH->setOrientation(Qt::Horizontal); + + QProgressBar* progreV = new QProgressBar(this); + progreV->move(100, 300); + progreV->resize(40, 250); + progreV->setValue(67); + progreV->setOrientation(Qt::Vertical); + + int i = 0; + QStringList listStyle = QStyleFactory::keys(); + foreach(QString val, listStyle) { //打印当前系统支持的系统风格 + qDebug()<move(this->rect().right() - 100, this->rect().top() + i++ * 40); + connect(btn, &QPushButton::clicked, this, [=](){ + qApp->setStyle(val); + }); + } + +} diff --git a/QtMyStyleEx/QtExample01/QtStyleEx/widget.h b/QtMyStyleEx/QtExample01/QtStyleEx/widget.h new file mode 100644 index 0000000..412323f --- /dev/null +++ b/QtMyStyleEx/QtExample01/QtStyleEx/widget.h @@ -0,0 +1,17 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include + +class Widget : public QWidget +{ + Q_OBJECT + +public: + Widget(QWidget *parent = 0); + ~Widget(); + + void init(); +}; + +#endif // WIDGET_H