feat: 主要是构建自定义的枚举,Qt自带的枚举的扩展
This commit is contained in:
parent
f4c5a7435b
commit
0e576ff9aa
@ -16,7 +16,7 @@ void ExCustomStyle::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOptio
|
||||
void ExCustomStyle::drawControl(QStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w) const
|
||||
{
|
||||
switch (element) {
|
||||
//滚动条+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
//滚动条-------------------------------------
|
||||
case CE_ScrollBarAddPage: { //增加页(在滑槽)
|
||||
p->fillRect(opt->rect, Qt::green);
|
||||
break;
|
||||
@ -27,6 +27,7 @@ void ExCustomStyle::drawControl(QStyle::ControlElement element, const QStyleOpti
|
||||
}
|
||||
case CE_ScrollBarSlider: { //滑块
|
||||
p->fillRect(opt->rect, Qt::red);
|
||||
// p->setBrush();
|
||||
break;
|
||||
}
|
||||
case CE_ScrollBarAddLine: { //增加按钮
|
||||
|
@ -22,16 +22,82 @@ class ExCustomStyle : public QCommonStyle
|
||||
public:
|
||||
ExCustomStyle();
|
||||
|
||||
public: //重写QCommonStyle重载的函数
|
||||
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const override;
|
||||
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w) const override;
|
||||
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget) const override;
|
||||
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const override;
|
||||
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w) const override;
|
||||
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const override;
|
||||
virtual QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const override;
|
||||
|
||||
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 (均无关于元对象系统)
|
||||
|
||||
|
||||
//内联函数,然后自己选择是调用静态函数,还是重写的基类的函数
|
||||
inline void drawPrimitive(ExCustomStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const
|
||||
{ proxy()->drawPrimitive(static_cast<QStyle::PrimitiveElement>(pe), opt, p, w); }
|
||||
|
||||
|
||||
|
||||
//重写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 polish(QPalette &palette) override; //通常在此函数内指定配色方案,也即配置调色板
|
||||
// virtual void polish(QWidget *widget) override; //当样式应用到窗口部件时,polish(QWidget*)就会调用,从而允许我们进行最后的定制
|
||||
// virtual void unpolish(QWidget *widget) override; //当动态改变样式的时候,unpolish就会调用,来撤销polish的影响。polish(QWidget*)一般用做窗口部件的事件过滤器。
|
||||
};
|
||||
|
||||
CUSTOMSTYLE_END_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user