feat: The custom control MySwitchButton has been implemented
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
#include "Example.h"
|
||||
|
||||
Example::Example(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
Example::~Example()
|
||||
{
|
||||
}
|
||||
|
@@ -1,14 +0,0 @@
|
||||
#ifndef EXAMPLE_H
|
||||
#define EXAMPLE_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class Example : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Example(QWidget *parent = nullptr);
|
||||
~Example();
|
||||
};
|
||||
#endif // EXAMPLE_H
|
@@ -65,31 +65,11 @@ QRect MyStyle::subElementRect(MyStyle::SubElement subElement, const QStyleOption
|
||||
return proxy()->subElementRect(static_cast<QStyle::SubElement>(subElement), option, widget);
|
||||
}
|
||||
|
||||
//void MyStyle::drawComplexControl(MyStyle::ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
//QRect MyStyle::subControlRect(MyStyle::ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const
|
||||
//{
|
||||
// return QRect();
|
||||
//}
|
||||
|
||||
int MyStyle::pixelMetric(MyStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
|
||||
{
|
||||
return proxy()->pixelMetric(static_cast<QStyle::PixelMetric>(metric), option, widget);
|
||||
}
|
||||
|
||||
//QSize MyStyle::sizeFromContents(MyStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w) const
|
||||
//{
|
||||
// return QSize();
|
||||
//}
|
||||
|
||||
//int MyStyle::styleHint(MyStyle::StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const
|
||||
//{
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
void MyStyle::polish(QWidget *widget)
|
||||
{
|
||||
QCommonStyle::polish(widget);
|
||||
|
@@ -64,22 +64,14 @@ public:
|
||||
static void drawPrimitive(const QStyle *style, MyStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr);
|
||||
static void drawControl(const QStyle *style, MyStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w);
|
||||
static QRect subElementRect(const QStyle *style, MyStyle::SubElement subElement, const QStyleOption *option, const QWidget *widget);
|
||||
// static void drawComplexControl(const QStyle *style, MyStyle::ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const;
|
||||
// static QRect subControlRect(const QStyle *style, MyStyle::ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const;
|
||||
static int pixelMetric(const QStyle *style, MyStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget);
|
||||
// static QSize sizeFromContents(const QStyle *style, MyStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w) const;
|
||||
// static int styleHint(const QStyle *style, MyStyle::StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const;
|
||||
|
||||
//新增加的枚举属 MyStyle:: , 之能够在此内敛函数里面调用
|
||||
//[主要用来绘画 自定义新增 的控件枚举 --> 实际调用在 下面的 virtual 里面绘画]
|
||||
inline void drawPrimitive(MyStyle::PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w = nullptr) const;
|
||||
inline void drawControl(MyStyle::ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w) const;
|
||||
inline QRect subElementRect(MyStyle::SubElement subElement, const QStyleOption *option, const QWidget *widget) const;
|
||||
// inline void drawComplexControl(MyStyle::ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *widget) const;
|
||||
// inline QRect subControlRect(MyStyle::ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const;
|
||||
inline int pixelMetric(MyStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const;
|
||||
// inline QSize sizeFromContents(MyStyle::ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w) const;
|
||||
// inline int styleHint(MyStyle::StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const;
|
||||
|
||||
//这里的快捷方式创建的枚举,都是不带QStyle:: ; 但是快捷方式的定义是带是QStyle:: , 此处声明的地方必须加上 QStyle:: /*后面改写更复杂的得写上MyStyle:: 因添加自定义的枚举*/
|
||||
//这里 override 的虚函数,只能够调用旧有的 QStyle:: 的函数
|
||||
@@ -135,10 +127,10 @@ public:
|
||||
MyStylePainter(QWidget* w);
|
||||
~MyStylePainter() {}
|
||||
|
||||
/*inline*/ void drawPrimitive(MyStyle::PrimitiveElement pe, const QStyleOption *opt);
|
||||
/*inline*/ void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption *opt);
|
||||
/*inline*/ void drawControl(MyStyle::ControlElement element, const QStyleOption *opt);
|
||||
/*inline*/ void drawControl(QStyle::ControlElement element, const QStyleOption *opt);
|
||||
void drawPrimitive(MyStyle::PrimitiveElement pe, const QStyleOption *opt);
|
||||
void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption *opt);
|
||||
void drawControl(MyStyle::ControlElement element, const QStyleOption *opt);
|
||||
void drawControl(QStyle::ControlElement element, const QStyleOption *opt);
|
||||
|
||||
private:
|
||||
QWidget* m_widget;
|
||||
|
@@ -67,7 +67,7 @@ void MySwitchButtonPrivate::init()
|
||||
check = false;
|
||||
q->setObjectName("MySwitchButton");
|
||||
q->setChecked(true);
|
||||
q->setCheckable(true); //clicked toggled douxuyaokauqi
|
||||
q->setCheckable(true); //clicked toggled 都需要开启
|
||||
q->connect(q, SIGNAL(clicked(bool)), q, SLOT(setChecked(bool)));
|
||||
}
|
||||
|
||||
|
@@ -1,28 +0,0 @@
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
CONFIG += c++11
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any Qt feature that has been marked 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 it uses 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
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
Example.cpp
|
||||
|
||||
HEADERS += \
|
||||
Example.h
|
||||
|
||||
# Default rules for deployment.
|
||||
qnx: target.path = /tmp/$${TARGET}/bin
|
||||
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
!isEmpty(target.path): INSTALLS += target
|
@@ -1,11 +0,0 @@
|
||||
#include "Example.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
Example w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
Reference in New Issue
Block a user