feat: delete QtCustomStyleEx files
之前此QtCustomStyleEx文件夹比较混乱(commit),中间夹杂着太多的QDialog相关的提交,在此删除吗然后重新创建相关的文件信息
This commit is contained in:
parent
8ac140b983
commit
1bbfcde872
BIN
QtCustomStyleEx/.DS_Store
vendored
BIN
QtCustomStyleEx/.DS_Store
vendored
Binary file not shown.
@ -1,215 +0,0 @@
|
|||||||
#include "ExCustomStyle.h"
|
|
||||||
|
|
||||||
CUSTOMSTYLE_BEDGIN_NAMESPACE
|
|
||||||
|
|
||||||
ExCustomStyle::ExCustomStyle()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//静态static的函数+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
void ExCustomStyle::drawPrimitive(const QStyle *style, ExCustomStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w)
|
|
||||||
{
|
|
||||||
// DStyleHelper dstyle(style);
|
|
||||||
switch (pe) {
|
|
||||||
// case value:
|
|
||||||
// break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExCustomStyle::drawControl(const QStyle *style, ExCustomStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w)
|
|
||||||
{
|
|
||||||
switch (element) {
|
|
||||||
// case CE_IconButton:
|
|
||||||
// break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int ExCustomStyle::pixelMetric(const QStyle *style, QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget)
|
|
||||||
{
|
|
||||||
//全部都是return 一个数值
|
|
||||||
// DStyleHelper dstyle(style);
|
|
||||||
switch (metric) {
|
|
||||||
case PM_FrameRadius:
|
|
||||||
|
|
||||||
return 8;
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect ExCustomStyle::subElementRect(const QStyle *style, ExCustomStyle::SubElement subElement, const QStyleOption *option, const QWidget *widget)
|
|
||||||
{
|
|
||||||
switch (subElement) {
|
|
||||||
// case SE_SwitchButtonGroove: {
|
|
||||||
// return option->rect;
|
|
||||||
// }
|
|
||||||
default:
|
|
||||||
return QRect(-1, -1, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize ExCustomStyle::sizeFromContents(const QStyle *style, ExCustomStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w)
|
|
||||||
{
|
|
||||||
switch (ct) {
|
|
||||||
// case CT_ButtonBoxButton: {
|
|
||||||
// QSize size(100, 100);
|
|
||||||
// return size;
|
|
||||||
// }
|
|
||||||
default:
|
|
||||||
return contentsSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon ExCustomStyle::standardIcon(const QStyle *style, ExCustomStyle::StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget)
|
|
||||||
{
|
|
||||||
//使用宏, 来表示方便和快捷
|
|
||||||
#define CASE_ICON(Value) \
|
|
||||||
case SP_##Value: { \
|
|
||||||
DStyledIconEngine *icon_engine = new DStyledIconEngine(DDrawUtils::draw##Value, QStringLiteral(#Value)); \
|
|
||||||
return QIcon(icon_engine); }
|
|
||||||
|
|
||||||
switch (standardIcon) {
|
|
||||||
// CASE_ICON(ForkElement)
|
|
||||||
// CASE_ICON(DecreaseElement)
|
|
||||||
// CASE_ICON(IncreaseElement)
|
|
||||||
// CASE_ICON(MarkElement)
|
|
||||||
// case SP_EditElement:
|
|
||||||
// return QIcon::fromTheme("edit");
|
|
||||||
// case SP_MediaVolumeLowElement:
|
|
||||||
// return QIcon::fromTheme("volume_low");
|
|
||||||
default:
|
|
||||||
return QIcon();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//内联inline的函数+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
//实际上,只需要在实现处添加inline,声明出不需要写inline
|
|
||||||
inline void ExCustomStyle::drawPrimitive(ExCustomStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const
|
|
||||||
{
|
|
||||||
proxy()->drawPrimitive(static_cast<QStyle::PrimitiveElement>(pe), opt, p, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void ExCustomStyle::drawControl(ExCustomStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w) const
|
|
||||||
{
|
|
||||||
proxy()->drawControl(static_cast<QStyle::ControlElement>(element), opt, p, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline QRect ExCustomStyle::subElementRect(ExCustomStyle::SubElement subElement, const QStyleOption *option, const QWidget *widget) const
|
|
||||||
{
|
|
||||||
proxy()->subElementRect(static_cast<QStyle::SubElement>(subElement), option, widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int ExCustomStyle::pixelMetric(ExCustomStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
|
|
||||||
{
|
|
||||||
proxy()->pixelMetric(static_cast<QStyle::PixelMetric>(metric), option, widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline QSize ExCustomStyle::sizeFromContents(ExCustomStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w) const
|
|
||||||
{
|
|
||||||
proxy()->sizeFromContents(static_cast<QStyle::ContentsType>(ct), opt, contentsSize, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline int ExCustomStyle::styleHint(ExCustomStyle::StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const
|
|
||||||
{
|
|
||||||
proxy()->styleHint(static_cast<QStyle::StyleHint>(stylehint), opt, widget, returnData);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline QIcon ExCustomStyle::standardIcon(ExCustomStyle::StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const
|
|
||||||
{
|
|
||||||
proxy()->standardIcon(static_cast<QStyle::StandardPixmap>(standardIcon), option, widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
//重写重载的函数====================================================================================================
|
|
||||||
void ExCustomStyle::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const
|
|
||||||
{
|
|
||||||
QCommonStyle::drawPrimitive(pe, opt, p, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExCustomStyle::drawControl(QStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w) const
|
|
||||||
{
|
|
||||||
// if (Q_UNLIKELY(element < QStyle::CE_CustomBase)) {
|
|
||||||
// return QCommonStyle::drawControl(element, opt, p, w);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// drawControl(this, static_cast<ControlElement>(element), opt, p, w);
|
|
||||||
|
|
||||||
switch (element) {
|
|
||||||
//滚动条-------------------------------------
|
|
||||||
case CE_ScrollBarAddPage: { //增加页(在滑槽)
|
|
||||||
p->fillRect(opt->rect, Qt::green);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CE_ScrollBarSubPage: { //减少页(在滑槽)
|
|
||||||
p->fillRect(opt->rect, Qt::gray);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CE_ScrollBarSlider: { //滑块
|
|
||||||
p->fillRect(opt->rect, Qt::red);
|
|
||||||
// p->setBrush();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CE_ScrollBarAddLine: { //增加按钮
|
|
||||||
p->fillRect(opt->rect, Qt::blue);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CE_ScrollBarSubLine: { //减少按钮
|
|
||||||
p->fillRect(opt->rect, Qt::magenta);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// case CE_ScrollBarFirst:
|
|
||||||
// case CE_ScrollBarLast: break; //未知
|
|
||||||
//END+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
QCommonStyle::drawControl(element, opt, p, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect ExCustomStyle::subElementRect(QStyle::SubElement subElement, const QStyleOption *option, const QWidget *widget) const
|
|
||||||
{
|
|
||||||
return QCommonStyle::subElementRect(subElement, option, widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ExCustomStyle::pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
|
|
||||||
{
|
|
||||||
return QCommonStyle::pixelMetric(metric, option, widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize ExCustomStyle::sizeFromContents(QStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w) const
|
|
||||||
{
|
|
||||||
return QCommonStyle::sizeFromContents(ct, opt, contentsSize, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ExCustomStyle::styleHint(QStyle::StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const
|
|
||||||
{
|
|
||||||
return QCommonStyle::styleHint(stylehint, opt, widget, returnData);
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon ExCustomStyle::standardIcon(QStyle::StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const
|
|
||||||
{
|
|
||||||
return QCommonStyle::standardIcon(standardIcon, option, widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExCustomStyle::drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const
|
|
||||||
{
|
|
||||||
return QCommonStyle::drawComplexControl(cc, opt, p, widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect ExCustomStyle::subControlRect(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const
|
|
||||||
{
|
|
||||||
return QCommonStyle::subControlRect(cc, opt, sc, widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStyle::SubControl ExCustomStyle::hitTestComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget) const
|
|
||||||
{
|
|
||||||
return QCommonStyle::hitTestComplexControl(cc, opt, pt, widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
//END+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
|
|
||||||
CUSTOMSTYLE_END_NAMESPACE
|
|
@ -1,131 +0,0 @@
|
|||||||
#ifndef EXCUSTOMSTYLE_H
|
|
||||||
#define EXCUSTOMSTYLE_H
|
|
||||||
|
|
||||||
//Qt自带的库
|
|
||||||
#include <QCommonStyle>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QStyleOption>
|
|
||||||
|
|
||||||
//自定义的文件或库
|
|
||||||
#include "ExDefineGlobal.h"
|
|
||||||
|
|
||||||
CUSTOMSTYLE_BEDGIN_NAMESPACE
|
|
||||||
|
|
||||||
//一些工具函数:绘画圈,叉,对号,阴影等功能函数
|
|
||||||
CUSTOM_BEGIN_NAMESPACE
|
|
||||||
CUSTOMSTYLE_END_NAMESPACE
|
|
||||||
|
|
||||||
class ExCustomStyle : public QCommonStyle
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
ExCustomStyle();
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum PrimitiveElement {
|
|
||||||
PE_ItemBackground = QStyle::PE_CustomBase + 1, //列表项的背景色
|
|
||||||
PE_SwitchButtonGroove,
|
|
||||||
PE_SwitchButtonHandle,
|
|
||||||
PE_CustomBase = QStyle::PE_CustomBase + 0xf00000
|
|
||||||
};
|
|
||||||
|
|
||||||
enum ControlElement {
|
|
||||||
CE_IconButton = QStyle::CE_CustomBase + 1,
|
|
||||||
CE_SwitchButton,
|
|
||||||
CE_CustomBase = QStyle::CE_CustomBase + 0xf00000
|
|
||||||
};
|
|
||||||
|
|
||||||
enum SubElement {
|
|
||||||
SE_IconButtonIcon = QStyle::SE_CustomBase + 1,
|
|
||||||
SE_SwitchButtonGroove,
|
|
||||||
SE_SwitchButtonHandle,
|
|
||||||
SE_CustomBase = QStyle::SE_CustomBase + 0xf00000
|
|
||||||
};
|
|
||||||
|
|
||||||
enum PixelMetric {
|
|
||||||
PM_FocusBorderWidth = QStyle::PM_CustomBase + 1, //控件焦点状态的边框宽度
|
|
||||||
PM_FrameRadius,
|
|
||||||
PM_CustomBase = QStyle::PM_CustomBase + 0xf00000
|
|
||||||
};
|
|
||||||
|
|
||||||
enum ContentsType {
|
|
||||||
CT_IconButton = QStyle::CT_CustomBase + 1,
|
|
||||||
CT_SwitchButton,
|
|
||||||
CT_CustomBase = QStyle::CT_CustomBase + 0xf00000
|
|
||||||
};
|
|
||||||
|
|
||||||
enum StyleHint {
|
|
||||||
SH_CustomBase = QStyle::SH_CustomBase + 0xf00000
|
|
||||||
};
|
|
||||||
|
|
||||||
enum StandardPixmap {
|
|
||||||
SP_CustomBase = QStyle::SP_CustomBase + 0xf00000
|
|
||||||
};
|
|
||||||
|
|
||||||
/*枚举通过按位 ~ ^ | !来计算得到需要组合
|
|
||||||
* //0b对应的二进制 0x十六进制 对应的十进制
|
|
||||||
* 0b0000 0001 0x0000 0001 1
|
|
||||||
* 0b0000 0010 0x0000 0002 2
|
|
||||||
* 0b0000 0100 0x0000 0004 4
|
|
||||||
* 0b0000 1000 0x0000 0006 8
|
|
||||||
* 0b0001 0000 0x0000 0010 16
|
|
||||||
*/
|
|
||||||
|
|
||||||
enum StyleState {
|
|
||||||
SS_NormalState = 0x00000000,
|
|
||||||
SS_HoverState = 0x00000001,
|
|
||||||
SS_PressState = 0x00000002,
|
|
||||||
};
|
|
||||||
Q_DECLARE_FLAGS(StateFlags, StyleState) //而类型定义(typedef)和操作符重载正是宏Q_DECLARE_FLAGS 和 Q_DECLARE_OPERATORS_FOR_FLAGS (均无关于元对象系统)
|
|
||||||
|
|
||||||
//静态static函数
|
|
||||||
static void drawPrimitive(const QStyle *style, ExCustomStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w);
|
|
||||||
static void drawControl(const QStyle *style, ExCustomStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w);
|
|
||||||
static int pixelMetric(const QStyle *style, QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget);
|
|
||||||
static QRect subElementRect(const QStyle *style, ExCustomStyle::SubElement subElement, const QStyleOption *option, const QWidget *widget);
|
|
||||||
static QSize sizeFromContents(const QStyle *style, ExCustomStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w);
|
|
||||||
static QIcon standardIcon(const QStyle *style, ExCustomStyle::StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget);
|
|
||||||
|
|
||||||
|
|
||||||
//内联inline函数,然后[自动选择]是调用静态函数,还是重写的基类的函数
|
|
||||||
inline void drawPrimitive(ExCustomStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const;
|
|
||||||
inline void drawControl(ExCustomStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w) const;
|
|
||||||
inline QRect subElementRect(ExCustomStyle::SubElement subElement, const QStyleOption *option, const QWidget *widget) const;
|
|
||||||
inline int pixelMetric(ExCustomStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const;
|
|
||||||
inline QSize sizeFromContents(ExCustomStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w) const;
|
|
||||||
inline int styleHint(ExCustomStyle::StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const;
|
|
||||||
inline QIcon standardIcon(ExCustomStyle::StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const;
|
|
||||||
// inline void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const; //这三个不用写成内联函数,且会编译不通过
|
|
||||||
// inline QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const;
|
|
||||||
// inline QStyle::SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget) const;
|
|
||||||
|
|
||||||
//重写QCommonStyle重载的函数
|
|
||||||
virtual void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const override;
|
|
||||||
virtual void drawControl(QStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w) const override;
|
|
||||||
virtual QRect subElementRect(QStyle::SubElement subElement, const QStyleOption *option, const QWidget *widget) const override;
|
|
||||||
virtual int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const override;
|
|
||||||
virtual QSize sizeFromContents(QStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w) const override;
|
|
||||||
virtual int styleHint(QStyle::StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const override;
|
|
||||||
virtual QIcon standardIcon(QStyle::StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const override;
|
|
||||||
|
|
||||||
virtual void drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const override;
|
|
||||||
virtual QRect subControlRect(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const override;
|
|
||||||
virtual SubControl hitTestComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *widget) const override;
|
|
||||||
|
|
||||||
// virtual void polish(QPalette &palette) override; //通常在此函数内指定配色方案,也即配置调色板
|
|
||||||
// virtual void polish(QWidget *widget) override; //当样式应用到窗口部件时,polish(QWidget*)就会调用,从而允许我们进行最后的定制
|
|
||||||
// virtual void unpolish(QWidget *widget) override; //当动态改变样式的时候,unpolish就会调用,来撤销polish的影响。polish(QWidget*)一般用做窗口部件的事件过滤器。
|
|
||||||
|
|
||||||
using QCommonStyle::drawPrimitive; //重实现,使得父类的多个同名 函数 (不同参数) 任然可以在本类里面使用
|
|
||||||
using QCommonStyle::drawControl;
|
|
||||||
using QCommonStyle::subElementRect;
|
|
||||||
using QCommonStyle::pixelMetric;
|
|
||||||
using QCommonStyle::sizeFromContents;
|
|
||||||
using QCommonStyle::styleHint;
|
|
||||||
using QCommonStyle::standardIcon;
|
|
||||||
};
|
|
||||||
|
|
||||||
CUSTOMSTYLE_END_NAMESPACE
|
|
||||||
|
|
||||||
#endif // EXCUSTOMSTYLE_H
|
|
@ -1,18 +0,0 @@
|
|||||||
#ifndef EXDEFINEGLOBAL_H
|
|
||||||
#define EXDEFINEGLOBAL_H
|
|
||||||
|
|
||||||
//用来定义一些宏的使用: 尝试写大项目的架构
|
|
||||||
|
|
||||||
//定义命名空间的宏(在定义 class ExCustomStyle: 的时候用到了 eg: ExCustomStyle.h ExCustomStyle.cpp里面)
|
|
||||||
#define CUSTOMSTYLE_BEDGIN_NAMESPACE namespace touwoyimuliStyle {
|
|
||||||
#define CUSTOMSTYLE_END_NAMESPACE }
|
|
||||||
|
|
||||||
#define CUSTOM_BEGIN_NAMESPACE namespace touwoyimuliDrawUtils { //嵌套于命名空间 touwoyimuliDrawUtils里面
|
|
||||||
#define CUSTOM_END_NAMESPACE }
|
|
||||||
|
|
||||||
//定义使用命名空间((在使用 class ExCustomStyle的定义内容时候用到了 eg:Examples.cpp里面))
|
|
||||||
#define CUSTOMSTYLE_USE_NAMESPACE using namespace touwoyimuliStyle;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // EXDEFINEGLOBAL_H
|
|
@ -1,54 +0,0 @@
|
|||||||
#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"));
|
|
||||||
qApp->setStyle(new ExCustomStyle());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
#ifndef EXAMPLES_H
|
|
||||||
#define EXAMPLES_H
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QStyleFactory>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include "ExCustomStyle.h"
|
|
||||||
|
|
||||||
namespace Ui {
|
|
||||||
class Examples;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Examples : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit Examples(QWidget *parent = nullptr);
|
|
||||||
~Examples();
|
|
||||||
|
|
||||||
void init(); //获取当前系统支持的默认系统风格
|
|
||||||
private slots:
|
|
||||||
void on_comboBox_currentIndexChanged(const QString &style);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::Examples *ui;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // EXAMPLES_H
|
|
@ -1,186 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>Examples</class>
|
|
||||||
<widget class="QWidget" name="Examples">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>1235</width>
|
|
||||||
<height>695</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>Examples</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
|
||||||
<property name="tabPosition">
|
|
||||||
<enum>QTabWidget::South</enum>
|
|
||||||
</property>
|
|
||||||
<property name="currentIndex">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<widget class="QWidget" name="tab">
|
|
||||||
<attribute name="title">
|
|
||||||
<string>滚动条</string>
|
|
||||||
</attribute>
|
|
||||||
<widget class="QWidget" name="gridLayoutWidget">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>10</x>
|
|
||||||
<y>10</y>
|
|
||||||
<width>441</width>
|
|
||||||
<height>251</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<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>470</x>
|
|
||||||
<y>10</y>
|
|
||||||
<width>135</width>
|
|
||||||
<height>31</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
|
||||||
<widget class="QWidget" name="tab_2">
|
|
||||||
<attribute name="title">
|
|
||||||
<string>Tab 2</string>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
@ -1,45 +0,0 @@
|
|||||||
#-------------------------------------------------
|
|
||||||
#
|
|
||||||
# Project created by QtCreator 2019-08-26T19:16:23
|
|
||||||
#
|
|
||||||
#-------------------------------------------------
|
|
||||||
|
|
||||||
QT += core gui
|
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
|
||||||
|
|
||||||
TARGET = QtCustomStyleEx
|
|
||||||
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 \
|
|
||||||
Examples.cpp \
|
|
||||||
ExCustomStyle.cpp
|
|
||||||
|
|
||||||
HEADERS += \
|
|
||||||
Examples.h \
|
|
||||||
ExCustomStyle.h \
|
|
||||||
ExDefineGlobal.h
|
|
||||||
|
|
||||||
FORMS += \
|
|
||||||
Examples.ui
|
|
||||||
|
|
||||||
RC_ICONS += qt.ico
|
|
||||||
|
|
||||||
# Default rules for deployment.
|
|
||||||
qnx: target.path = /tmp/$${TARGET}/bin
|
|
||||||
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
|
||||||
!isEmpty(target.path): INSTALLS += target
|
|
@ -1,24 +0,0 @@
|
|||||||
#include "Examples.h"
|
|
||||||
#include <QApplication>
|
|
||||||
|
|
||||||
#include <QStyleFactory>
|
|
||||||
#include <QDebug>
|
|
||||||
#include "ExCustomStyle.h"
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
QApplication a(argc, argv);
|
|
||||||
|
|
||||||
// //使用系统或者自定义的风格
|
|
||||||
// QStringList listStyle = QStyleFactory::keys();
|
|
||||||
// foreach(QString val, listStyle)
|
|
||||||
// qDebug()<<val<<" ";
|
|
||||||
// QStyleFactory::create("Fusion");
|
|
||||||
// ExCustomStyle* customStyle = new ExCustomStyle;
|
|
||||||
// qApp->setStyle(customStyle);
|
|
||||||
|
|
||||||
Examples w;
|
|
||||||
w.show();
|
|
||||||
|
|
||||||
return a.exec();
|
|
||||||
}
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB |
Loading…
Reference in New Issue
Block a user