feat: 创建系统自定义样式风格ExCustomStyle
搭建一个框架,但是继承的类QCommonStyle里面的对应的虚函数还有没有重写,和体验感受win和linux系统自带多种风格样式
This commit is contained in:
parent
4342e0091c
commit
03b0948c86
@ -1,6 +1,10 @@
|
||||
#include "ExCustomStyle.h"
|
||||
|
||||
CUSTOMSTYLE_BEDGIN_NAMESPACE
|
||||
|
||||
ExCustomStyle::ExCustomStyle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CUSTOMSTYLE_END_NAMESPACE
|
||||
|
@ -3,6 +3,10 @@
|
||||
|
||||
#include <QCommonStyle>
|
||||
|
||||
#include "ExDefineGlobal.h"
|
||||
|
||||
CUSTOMSTYLE_BEDGIN_NAMESPACE
|
||||
|
||||
class ExCustomStyle : public QCommonStyle
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -11,4 +15,6 @@ public:
|
||||
ExCustomStyle();
|
||||
};
|
||||
|
||||
CUSTOMSTYLE_END_NAMESPACE
|
||||
|
||||
#endif // EXCUSTOMSTYLE_H
|
||||
|
13
QtCustomStyleEx/ExDefineGlobal.h
Normal file
13
QtCustomStyleEx/ExDefineGlobal.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef EXDEFINEGLOBAL_H
|
||||
#define EXDEFINEGLOBAL_H
|
||||
|
||||
//用来定义一些宏的使用: 尝试写大项目的架构
|
||||
|
||||
//定义命名空间的宏(在定义 class ExCustomStyle: 的时候用到了 eg: ExCustomStyle.h ExCustomStyle.cpp里面)
|
||||
#define CUSTOMSTYLE_BEDGIN_NAMESPACE namespace touwoyimuliStyle {
|
||||
#define CUSTOMSTYLE_END_NAMESPACE }
|
||||
|
||||
//定义使用命名空间((在使用 class ExCustomStyle的定义内容时候用到了 eg:Examples.cpp里面))
|
||||
#define CUSTOMSTYLE_USE_NAMESPACE using namespace touwoyimuliStyle;
|
||||
|
||||
#endif // EXDEFINEGLOBAL_H
|
@ -1,15 +1,53 @@
|
||||
#include "Examples.h"
|
||||
#include "ui_Examples.h"
|
||||
|
||||
CUSTOMSTYLE_USE_NAMESPACE
|
||||
|
||||
Examples::Examples(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::Examples)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowTitle(QObject::tr("创建自定义的CustomStyle风格"));
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
Examples::~Examples()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
//获取当前系统支持的默认系统风格
|
||||
void Examples::init()
|
||||
{
|
||||
//当前系统支持的系统风格,放入QcomboBox的item里面,且打印出来
|
||||
QStringList listStyle = QStyleFactory::keys();
|
||||
foreach(QString val, listStyle) {
|
||||
ui->comboBox->addItem(val);
|
||||
qDebug()<<val;
|
||||
}
|
||||
|
||||
//设置一个默认的风格
|
||||
ui->comboBox->addItem("ExCustomStyle");
|
||||
qApp->setStyle(QStyleFactory::create("Fusion"));
|
||||
}
|
||||
|
||||
|
||||
void Examples::on_comboBox_currentIndexChanged(const QString &style)
|
||||
{
|
||||
// qDebug()<<"当前选中的风格:"<<style;
|
||||
//当前选中item项为系统预支持的风格
|
||||
QStringList listStyle = QStyleFactory::keys();
|
||||
foreach(QString val, listStyle) {
|
||||
if (style == val) {
|
||||
qApp->setStyle(QStyleFactory::create(style));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//不属于系统风格,则使用自己的风格
|
||||
ExCustomStyle* customStyle = new ExCustomStyle;
|
||||
qApp->setStyle(customStyle);
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,10 @@
|
||||
#define EXAMPLES_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QStyleFactory>
|
||||
#include <QDebug>
|
||||
|
||||
#include "ExCustomStyle.h"
|
||||
|
||||
namespace Ui {
|
||||
class Examples;
|
||||
@ -15,6 +19,10 @@ public:
|
||||
explicit Examples(QWidget *parent = nullptr);
|
||||
~Examples();
|
||||
|
||||
void init(); //获取当前系统支持的默认系统风格
|
||||
private slots:
|
||||
void on_comboBox_currentIndexChanged(const QString &style);
|
||||
|
||||
private:
|
||||
Ui::Examples *ui;
|
||||
};
|
||||
|
@ -26,141 +26,149 @@
|
||||
<attribute name="title">
|
||||
<string>滚动条</string>
|
||||
</attribute>
|
||||
<widget class="QScrollBar" name="scrollBarHor">
|
||||
<widget class="QWidget" name="gridLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>280</y>
|
||||
<width>531</width>
|
||||
<height>31</height>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>441</width>
|
||||
<height>251</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QScrollBar" name="scrollBarVer">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>540</x>
|
||||
<y>40</y>
|
||||
<width>31</width>
|
||||
<height>191</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
<y>60</y>
|
||||
<width>431</width>
|
||||
<height>161</height>
|
||||
</rect>
|
||||
</property>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>a</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>b</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>c</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>d</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>e</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>f</string>
|
||||
</property>
|
||||
</row>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>2</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>3</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>4</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>5</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>6</string>
|
||||
</property>
|
||||
</column>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>400</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>a</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>b</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>c</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>d</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>e</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>f</string>
|
||||
</property>
|
||||
</row>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>1</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>2</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>3</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>4</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>5</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>6</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QScrollBar" name="scrollBarHor">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" rowspan="2">
|
||||
<widget class="QScrollBar" name="scrollBarVer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>650</x>
|
||||
<y>40</y>
|
||||
<width>131</width>
|
||||
<height>22</height>
|
||||
<x>470</x>
|
||||
<y>10</y>
|
||||
<width>135</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Windows</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>New Item</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>WindowsXP</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>WindowsVista</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Fusion</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>ExCustomStyle</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_2">
|
||||
|
@ -31,12 +31,13 @@ SOURCES += \
|
||||
|
||||
HEADERS += \
|
||||
Examples.h \
|
||||
ExCustomStyle.h
|
||||
ExCustomStyle.h \
|
||||
ExDefineGlobal.h
|
||||
|
||||
FORMS += \
|
||||
Examples.ui
|
||||
|
||||
RC_ICONS += QT_win_32x32.ico
|
||||
RC_ICONS += qt.ico
|
||||
|
||||
# Default rules for deployment.
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
|
@ -9,7 +9,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
//使用系统或者自定义的风格
|
||||
// //使用系统或者自定义的风格
|
||||
// QStringList listStyle = QStyleFactory::keys();
|
||||
// foreach(QString val, listStyle)
|
||||
// qDebug()<<val<<" ";
|
||||
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
39
README.md
39
README.md
@ -17,7 +17,7 @@
|
||||
## 说明:
|
||||
|
||||
会将该系列的源码,文章等系列,全部托管于这个仓库,该系列的主线任务只是讲解qt的相关文章。
|
||||
|
||||
|
||||
<font color=#70AD47 size=4 face="幼圆">**开发环境:**</font> `win10 x64 专业版 1803` <font color=#70AD47 size=4 face="幼圆">**操作系统版本**</font>:`17134.829`
|
||||
|
||||
<font color=#70AD47 size=4 face="幼圆">**开发软件:** </font> `Qt Creator 4.8.2 (Enterprise)` 、 `Qt 5.9.8`
|
||||
@ -39,15 +39,31 @@
|
||||
- `Qt Creator` **IDE**的界面组成和使用讲解
|
||||
- 编写一个**qt**的第一个项目: `Hello World`的项目
|
||||
|
||||
|
||||
## 第二部分:qt生成原理/运行机制
|
||||
|
||||
- [`make` `makefile` `cmake` `qmake`都是什么,有什么区别?](https://blog.csdn.net/qq_33154343/article/details/98170236)
|
||||
|
||||
|
||||
## 第三部分:常用控件
|
||||
|
||||
- 一个默认的`Qt Widget`项目 【空】
|
||||
- 元对象系统`moc`(**Meat-Object System**)的对象`MetaObject`和(含动态)属性`Propert`的用法【QtMeatObjectEx】
|
||||
- 初识`QString`函数,用`QString`显示2/8/10/16进制互相转化 【QtQStringEx】
|
||||
- `QString`常用的功能函数的介绍和用法 【QtQStringFunEx】
|
||||
- `QSlider`的介绍和用法【QtQSliderEx】
|
||||
- `QSlider`移动条、`QScrollBar`滚动条、`QProgressBar`进度条控件的联动【QtQProgressBarEx】
|
||||
- `QSlider`仪表盘的用法【QtQdialQLCDEx】
|
||||
- 时间日期(`QTime`/`QDate`/`QDateTime`)和定时器(`QTimer`)的介绍和使用 【QtDateTimeEx】
|
||||
- `QComboBox`(下拉列表框)和`QPlainTextEdit`(多行富文本编辑器)的用法 【QtQcomboBoxEx】
|
||||
|
||||
<br>
|
||||
|
||||
## 第四部分:自定义风格样式QStyle
|
||||
|
||||
- 自定义`QStyle`界面所有控件的风格,换肤效果的教程,自定义继承`QCommonStyle`的风格类【QtCustomStyleEx】
|
||||
- 预备知识:`QStyle`、`QCommonStyle`d等讲解
|
||||
- [更换`Qt`应用程序的界面`UI`,实现换肤,改用自带其他默认`QStyle`风格样式](https://mp.csdn.net/mdeditor/100148539#)
|
||||
|
||||
<br>
|
||||
|
||||
## 补充部分:补充较杂的知识点
|
||||
|
||||
@ -60,17 +76,22 @@
|
||||
- [qt中文乱码问题](https://blog.csdn.net/qq_33154343/article/details/78686103)
|
||||
- [借Qt中文乱码谈谈Coding中的编码问题](https://blog.csdn.net/qq_33154343/article/details/78686075)
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
- [Qt5与Qt4的信号接收差异](https://blog.csdn.net/qq_33154343/article/details/79130732)
|
||||
|
||||
- `qt`的信号和槽关系
|
||||
- `qt`中Lam表达式
|
||||
|
||||
###
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
|
||||
## Qt推倒重学系列--总目录:
|
||||
|
||||
[github.io](https://touwoyimuli.github.io/)版本的**总目录**:
|
||||
|
||||
|
||||
|
||||
## 编译
|
||||
|
||||
倘若自己的个人版本,不同于作者,且又编译运行屡次失败,**靠谱方法**:请重装系统之后,安装与我的同一版本,发开编程环境[qt-opensource-windows-x86-5.9.8.exe](http://download.qt.io/archive/qt/5.9/5.9.8/qt-opensource-windows-x86-5.9.8.exe)。 请使用下载**这一版本**5.9.8的`QtCreator`编译运行项目,可以保证运行成功 (使用Desktop Qt 5.9.8 MinGW 32 bit 直接编译运行)
|
||||
@ -78,8 +99,8 @@
|
||||
<br>
|
||||
|
||||
## 互助
|
||||
若是帮助到了你,可以点击该项目的的<img src="https://raw.githubusercontent.com/touwoyimuli/FigureBed/master/project_log/20190709023321.png" height="18" width="18"/> **Star** 和<img src="https://raw.githubusercontent.com/touwoyimuli/FigureBed/master/project_log/20190709023317.png" height="18" width="18"/> **Fork** 的两个图标,方便抬手之间,表示点个赞,手有余香
|
||||
|
||||
若是帮助到了你,可以点击该项目的的<img src="https://raw.githubusercontent.com/touwoyimuli/FigureBed/master/project_log/20190709023321.png" height="18" width="18"/> **Star** 和<img src="https://raw.githubusercontent.com/touwoyimuli/FigureBed/master/project_log/20190709023317.png" height="18" width="18"/> **Fork** 的两个图标,方便抬手之间,表示点个赞,手有余香
|
||||
|
||||
<br>
|
||||
|
||||
@ -97,4 +118,4 @@
|
||||
|
||||
<img src='https://raw.githubusercontent.com/touwoyimuli/FigureBed/master/project_log/20190709052153.jpg' width='127' height='127'/>
|
||||
|
||||
<font color=#70AD47 size=4 face="幼圆">**touwoyimuli:** </font> 所含文章使用以下协议进行保护:[署名-非商业性使用-禁止演绎](http://creativecommons.org/licenses/by-nc-nd/3.0/cn/)。
|
||||
<font color=#70AD47 size=4 face="幼圆">**touwoyimuli:** </font> 所含文章使用以下协议进行保护:[署名-非商业性使用-禁止演绎](http://creativecommons.org/licenses/by-nc-nd/3.0/cn/)。
|
Loading…
Reference in New Issue
Block a user