From 76f5be9614a4084de652c18be795f463fe70e068 Mon Sep 17 00:00:00 2001 From: touwoyimuli Date: Fri, 6 Dec 2019 00:04:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20v1.4=20=E6=B7=BB=E5=8A=A0=E5=92=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=B8=80=E4=B8=AA=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E6=8E=A7=E4=BB=B6=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QtCustomStyleEx/MyWidget/ExSwitchButton.cpp | 70 +++++++++++++++++++++ QtCustomStyleEx/MyWidget/ExSwitchButton.h | 44 +++++++++++++ QtCustomStyleEx/MyWidget/ExSwitchButton_p.h | 51 +++++++++++++++ QtCustomStyleEx/QtCustomStyleEx.pro | 7 ++- 4 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 QtCustomStyleEx/MyWidget/ExSwitchButton.cpp create mode 100644 QtCustomStyleEx/MyWidget/ExSwitchButton.h create mode 100644 QtCustomStyleEx/MyWidget/ExSwitchButton_p.h diff --git a/QtCustomStyleEx/MyWidget/ExSwitchButton.cpp b/QtCustomStyleEx/MyWidget/ExSwitchButton.cpp new file mode 100644 index 0000000..162a0bd --- /dev/null +++ b/QtCustomStyleEx/MyWidget/ExSwitchButton.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2019 ~ 2019 touwoyimuli. All rights reserved. + * + * Author: touwoyimuli + * + * github: https://github.com/touwoyimuli + * blogs: https://touwoyimuli.github.io/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "ExSwitchButton.h" +//#include "qglobal.h" + +EXWIDGET_BEGIN_NAMESPACE + +//xxxPrivate class 会在 xxx.cpp 里面来实现 +/*! + * \~chinese \brief ExSwitchButtonPrivate 的构造函数 + */ +ExSwitchButtonPrivate::ExSwitchButtonPrivate(ExSwitchButton *qq) +{ + +} + +ExSwitchButtonPrivate::~ExSwitchButtonPrivate() +{ + +} + +void ExSwitchButtonPrivate::init() +{ + m_checked = false; //xxxxPrivate 自带的变量 + Q_Q(ExSwitchButton); //Q_Q 可以在 xxxxPrivate 里面调用 xxxx 的方法和变量 + + q->setObjectName("ExSwitchButtonPrivate"); + q->setCheckable(true); + q->connect(q, SIGNAL(toggled(bool)), q, SLOT(onChange(bool))); + +} + +ExSwitchButtonPrivate::ExSwitchButton() +{ + +} + +void ExSwitchButton::onChange(bool) +{ + Q_D(ExSwitchButton); + + d->m_checked = (!d->m_checked); + + qDebug()<<"------01-----ExSwitchButton::onChange(bool):"<m_checked; +} + + + + + +EXWIDGET_END_NAMESPACE diff --git a/QtCustomStyleEx/MyWidget/ExSwitchButton.h b/QtCustomStyleEx/MyWidget/ExSwitchButton.h new file mode 100644 index 0000000..3fb9857 --- /dev/null +++ b/QtCustomStyleEx/MyWidget/ExSwitchButton.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019 ~ 2019 touwoyimuli. All rights reserved. + * + * Author: touwoyimuli + * + * github: https://github.com/touwoyimuli + * blogs: https://touwoyimuli.github.io/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef EXSWITCHBUTTON_H +#define EXSWITCHBUTTON_H + +#include "ExMyGlobal.h" +#include "ExSwitchButton_p.h" + +#include + +EXWIDGET_BEGIN_NAMESPACE + +class ExSwitchButton : public QAbstractButton +{ +public: + explicit ExSwitchButton(); + ~ExSwitchButton(); + +private slots: + void onChange(bool); +}; + +EXWIDGET_END_NAMESPACE + +#endif diff --git a/QtCustomStyleEx/MyWidget/ExSwitchButton_p.h b/QtCustomStyleEx/MyWidget/ExSwitchButton_p.h new file mode 100644 index 0000000..12b30a2 --- /dev/null +++ b/QtCustomStyleEx/MyWidget/ExSwitchButton_p.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 ~ 2019 touwoyimuli. All rights reserved. + * + * Author: touwoyimuli + * + * github: https://github.com/touwoyimuli + * blogs: https://touwoyimuli.github.io/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef EXSWITCHBUTTON_P_H +#define EXSWITCHBUTTON_P_H + +#include "ExMyGlobal.h" +#include + +EXWIDGET_BEGIN_NAMESPACE + +/*! + * \~chinese \class ExSwitchButtonPrivate + * \~chinese \brief ExSwitchButton 类的数据类, 便于实现源码/二进制兼容, 通常继承于 “自定义_Private” 的类 + * \~chinese \sa Qt 自带的 QPushButtonPrivate, QPushButton 实现 + */ + +class ExSwitchButton; +class ExSwitchButtonPrivate //自定义控件通常继承于 QObjectPrivate 之类的 +{ +public: + ExSwitchButtonPrivate(ExSwitchButton *qq); + ~ExSwitchButtonPrivate(); + + void init(); + +public: + bool m_checked; //switch 是否处于开启状态 +}; + +EXWIDGET_END_NAMESPACE + +#endif diff --git a/QtCustomStyleEx/QtCustomStyleEx.pro b/QtCustomStyleEx/QtCustomStyleEx.pro index f488713..d7ce2c4 100644 --- a/QtCustomStyleEx/QtCustomStyleEx.pro +++ b/QtCustomStyleEx/QtCustomStyleEx.pro @@ -27,12 +27,15 @@ CONFIG += c++11 SOURCES += \ main.cpp \ Example.cpp \ - ExMyStyle.cpp + ExMyStyle.cpp \ + MyWidget/ExSwitchButton.cpp HEADERS += \ Example.h \ ExMyStyle.h \ - ExMyGlobal.h + ExMyGlobal.h \ + MyWidget/ExSwitchButton.h \ + MyWidget/ExSwitchButton_p.h # Default rules for deployment.