diff --git a/QtCustomStyleEx/ExMyStyle.cpp b/QtCustomStyleEx/ExMyStyle.cpp new file mode 100644 index 0000000..978c7f1 --- /dev/null +++ b/QtCustomStyleEx/ExMyStyle.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2019 ~ 2019 touwoyimuli. All rights reserved. + * + * Author: touwoyimuli + * + * github: https://github.com/touwoyimuli + * blogs: https://touwoyimuli.github.io/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "ExMyStyle.h" + +ExMyStyle::ExMyStyle() +{ + +} diff --git a/QtCustomStyleEx/ExMyStyle.h b/QtCustomStyleEx/ExMyStyle.h new file mode 100644 index 0000000..4746208 --- /dev/null +++ b/QtCustomStyleEx/ExMyStyle.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2019 ~ 2019 touwoyimuli. All rights reserved. + * + * Author: touwoyimuli + * + * github: https://github.com/touwoyimuli + * blogs: https://touwoyimuli.github.io/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef EXMYSTYLE_H +#define EXMYSTYLE_H + +#include + + +class ExMyStyle : public QCommonStyle +{ +public: + ExMyStyle(); +}; + +#endif // EXMYSTYLE_H diff --git a/QtCustomStyleEx/Example.cpp b/QtCustomStyleEx/Example.cpp index c75ddca..08eb033 100644 --- a/QtCustomStyleEx/Example.cpp +++ b/QtCustomStyleEx/Example.cpp @@ -1,11 +1,69 @@ +/* + * Copyright (C) 2019 ~ 2019 touwoyimuli. All rights reserved. + * + * Author: touwoyimuli + * + * github: https://github.com/touwoyimuli + * blogs: https://touwoyimuli.github.io/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "Example.h" Example::Example(QWidget *parent) : QWidget(parent) { + } Example::~Example() { } + +void Example::init() +{ + QTableWidget *table = new QTableWidget(10, 10, this); + QProgressBar *progressH = new QProgressBar(this); + QProgressBar *progressV = new QProgressBar(this); + + table->move(10, 10); + + progressH->move(300, 50); + progressH->setRange(0, 100); + progressH->setValue(34); + progressH->resize(380, 40); + + progressV->move(50, 250); + progressV->setRange(0, 100); + progressV->setValue(67); + progressV->resize(50, 380); + progressV->setOrientation(Qt::Vertical); + + int i = 0; + QStringList listStyle = QStyleFactory::keys(); + foreach(QString val, listStyle) { //打印当前系统支持的系统风格 + QPushButton *btn = new QPushButton(val, this); + btn->move(this->rect().right() - 100, this->rect().top() + i++ * 40); + connect(btn, &QPushButton::clicked, this, [=](){ + qApp->setStyle(val); + }); + } + + QPushButton *btn = new QPushButton("ExMyStyle", this); + btn->move(this->rect().right() - 100, this->rect().top() + i++ * 40); + connect(btn, &QPushButton::clicked, this, [=](){ + qApp->setStyle(QStyleFactory::create("ExMyStyle")); + }); +} diff --git a/QtCustomStyleEx/Example.h b/QtCustomStyleEx/Example.h index 13bee3d..82ef9e8 100644 --- a/QtCustomStyleEx/Example.h +++ b/QtCustomStyleEx/Example.h @@ -22,7 +22,15 @@ #ifndef EXAMPLE_H #define EXAMPLE_H +#include +#include #include +#include +#include +#include +#include + +#include "ExMyStyle.h" class Example : public QWidget { @@ -31,6 +39,8 @@ class Example : public QWidget public: Example(QWidget *parent = 0); ~Example(); + + void init(); }; #endif // EXAMPLE_H diff --git a/QtCustomStyleEx/QtCustomStyleEx.pro b/QtCustomStyleEx/QtCustomStyleEx.pro index c344667..181f14d 100644 --- a/QtCustomStyleEx/QtCustomStyleEx.pro +++ b/QtCustomStyleEx/QtCustomStyleEx.pro @@ -26,10 +26,13 @@ CONFIG += c++11 SOURCES += \ main.cpp \ - Example.cpp + Example.cpp \ + ExMyStyle.cpp HEADERS += \ - Example.h + Example.h \ + ExMyStyle.h + # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/QtCustomStyleEx/main.cpp b/QtCustomStyleEx/main.cpp index 6cf32ca..89d89ff 100644 --- a/QtCustomStyleEx/main.cpp +++ b/QtCustomStyleEx/main.cpp @@ -21,12 +21,24 @@ */ #include "Example.h" #include +#include +#include int main(int argc, char *argv[]) { QApplication a(argc, argv); - Example w; - w.show(); + + //若为系统自带的QStyle,则qApp->setStyle("系统自带风格"); + //若为自定义新的QStyle,则qApp->setStyle(QStyleFactory::create("自定义风格")) + QStringList listStyle = QStyleFactory::keys(); + foreach(QString val, listStyle) //打印当前系统支持的系统风格 + qDebug()<setStyle("chameleon"); //Windows/Fusion/... + Example *w = new Example(); + w->resize(1000, 700); + w->init(); + w->show(); return a.exec(); }