From 1565858861e3ef6fe4a35e0b52b2fee04c24c406 Mon Sep 17 00:00:00 2001 From: touwoyimuli Date: Wed, 11 Dec 2019 00:12:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20v1.4.2=20=E5=88=9B=E5=BB=BA=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=B1=BB=20ExSwitchButton=20=E5=92=8C=20ExSwitchButto?= =?UTF-8?q?nPrivate=20=E7=B1=BB=E6=88=90=E5=8A=9F=EF=BC=8C=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E4=BA=86q=5Ffun()=20=E5=92=8C=20d=5Ffun()=20=E7=9A=84?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E4=B8=8D=E9=80=9A=E8=BF=87=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QtCustomStyleEx/Example.cpp | 2 ++ QtCustomStyleEx/MyWidget/ExSwitchButton.cpp | 15 ++++----------- QtCustomStyleEx/MyWidget/ExSwitchButton.h | 7 +++++-- QtCustomStyleEx/MyWidget/ExSwitchButton_p.h | 10 +++++++--- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/QtCustomStyleEx/Example.cpp b/QtCustomStyleEx/Example.cpp index 4136678..bc8a47a 100644 --- a/QtCustomStyleEx/Example.cpp +++ b/QtCustomStyleEx/Example.cpp @@ -30,6 +30,8 @@ #include #include +#include "MyWidget/ExSwitchButton.h" + EXWIDGET_USE_NAMESPACE Example::Example(QWidget *parent) diff --git a/QtCustomStyleEx/MyWidget/ExSwitchButton.cpp b/QtCustomStyleEx/MyWidget/ExSwitchButton.cpp index 45c3b3b..fa8bfb8 100644 --- a/QtCustomStyleEx/MyWidget/ExSwitchButton.cpp +++ b/QtCustomStyleEx/MyWidget/ExSwitchButton.cpp @@ -20,8 +20,8 @@ * along with this program. If not, see . */ #include "ExSwitchButton.h" -//#include "qglobal.h" - +#include "ExSwitchButton_p.h" +#include EXWIDGET_BEGIN_NAMESPACE @@ -29,7 +29,7 @@ EXWIDGET_BEGIN_NAMESPACE /*! * \~chinese \brief ExSwitchButtonPrivate 的构造函数 */ -ExSwitchButtonPrivate::ExSwitchButtonPrivate(ExSwitchButton *qq) +ExSwitchButtonPrivate::ExSwitchButtonPrivate(/*ExSwitchButton *qq*/) { } @@ -48,11 +48,7 @@ void ExSwitchButtonPrivate::init() q->setCheckable(true); q->connect(q, SIGNAL(toggled(bool)), q, SLOT(onChange(bool))); -} - -ExSwitchButtonPrivate::ExSwitchButton() -{ - + q->onChange(true); } void ExSwitchButton::onChange(bool) @@ -65,7 +61,4 @@ void ExSwitchButton::onChange(bool) } - - - EXWIDGET_END_NAMESPACE diff --git a/QtCustomStyleEx/MyWidget/ExSwitchButton.h b/QtCustomStyleEx/MyWidget/ExSwitchButton.h index d2d3cd3..7606fc1 100644 --- a/QtCustomStyleEx/MyWidget/ExSwitchButton.h +++ b/QtCustomStyleEx/MyWidget/ExSwitchButton.h @@ -23,21 +23,24 @@ #define EXSWITCHBUTTON_H #include "ExMyGlobal.h" -#include "ExSwitchButton_p.h" +#include #include EXWIDGET_BEGIN_NAMESPACE +class ExSwitchButtonPrivate; //Q_DECLARE_PRIVATE() 宏展开使用的 class ExSwitchButton : public QAbstractButton { - Q_OBJECT public: explicit ExSwitchButton(); ~ExSwitchButton(); private slots: void onChange(bool); + +private: + Q_DECLARE_PRIVATE(ExSwitchButton) }; EXWIDGET_END_NAMESPACE diff --git a/QtCustomStyleEx/MyWidget/ExSwitchButton_p.h b/QtCustomStyleEx/MyWidget/ExSwitchButton_p.h index 2c4ef74..36b8aad 100644 --- a/QtCustomStyleEx/MyWidget/ExSwitchButton_p.h +++ b/QtCustomStyleEx/MyWidget/ExSwitchButton_p.h @@ -36,16 +36,20 @@ EXWIDGET_BEGIN_NAMESPACE * \~chinese \sa Qt 自带的 QPushButtonPrivate, QPushButton 实现 */ -class ExSwitchButton; -class ExSwitchButtonPrivate : public QObjectPrivate { + +class ExSwitchButtonPrivate : public QObjectPrivate +{ public: - ExSwitchButtonPrivate(ExSwitchButton *qq); + explicit ExSwitchButtonPrivate(); ~ExSwitchButtonPrivate(); void init(); public: bool m_checked; //switch 是否处于开启状态 + +public: + Q_DECLARE_PUBLIC(ExSwitchButton) //要加上宏 }; EXWIDGET_END_NAMESPACE