From 3618396389efc9bb1e7ca01282565a38a361b245 Mon Sep 17 00:00:00 2001 From: michapet Date: Tue, 15 Oct 2019 10:48:58 +0200 Subject: [PATCH 1/3] toggled slot created slot for toggled method and moved lambda function to the method. --- Section.cpp | 17 ++++++++++------- Section.h | 8 +++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Section.cpp b/Section.cpp index f73fdd1..49788cc 100644 --- a/Section.cpp +++ b/Section.cpp @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with Elypson/qt-collapsible-section. If not, see . -*/ +*/ #include @@ -62,14 +62,17 @@ Section::Section(const QString & title, const int animationDuration, QWidget* pa mainLayout->addWidget(contentArea, row, 0, 1, 3); setLayout(mainLayout); - QObject::connect(toggleButton, &QToolButton::toggled, [this](const bool checked) - { - toggleButton->setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow); - toggleAnimation->setDirection(checked ? QAbstractAnimation::Forward : QAbstractAnimation::Backward); - toggleAnimation->start(); - }); + connect(toggleButton, SIGNAL(toggled(bool)), this, SLOT(toggled(bool))); } + +void Section::toggled(bool collapsed) { + toggleButton->setArrowType(collapsed ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow); + toggleAnimation->setDirection(collapsed ? QAbstractAnimation::Forward : QAbstractAnimation::Backward); + toggleAnimation->start(); +} + + void Section::setContentLayout(QLayout & contentLayout) { delete contentArea->layout(); diff --git a/Section.h b/Section.h index a5552d9..f66a932 100644 --- a/Section.h +++ b/Section.h @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with Elypson/qt-collapsible-section. If not, see . -*/ +*/ #ifndef SECTION_H #define SECTION_H @@ -39,6 +39,12 @@ class Section : public QWidget { QScrollArea* contentArea; int animationDuration; + +public slots: + + void toggled(bool collapsed); + + public: explicit Section(const QString & title = "", const int animationDuration = 100, QWidget* parent = 0); From 3e7b32c5cbc28e425d7118ef62b74039be505068 Mon Sep 17 00:00:00 2001 From: michail-peterlis Date: Tue, 15 Oct 2019 12:18:25 +0200 Subject: [PATCH 2/3] renamed slot --- Section.cpp | 4 ++-- Section.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Section.cpp b/Section.cpp index 49788cc..bd9b33e 100644 --- a/Section.cpp +++ b/Section.cpp @@ -62,11 +62,11 @@ Section::Section(const QString & title, const int animationDuration, QWidget* pa mainLayout->addWidget(contentArea, row, 0, 1, 3); setLayout(mainLayout); - connect(toggleButton, SIGNAL(toggled(bool)), this, SLOT(toggled(bool))); + connect(toggleButton, SIGNAL(toggled(bool)), this, SLOT(toggle(bool))); } -void Section::toggled(bool collapsed) { +void Section::toggle(bool collapsed) { toggleButton->setArrowType(collapsed ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow); toggleAnimation->setDirection(collapsed ? QAbstractAnimation::Forward : QAbstractAnimation::Backward); toggleAnimation->start(); diff --git a/Section.h b/Section.h index f66a932..4053d44 100644 --- a/Section.h +++ b/Section.h @@ -42,7 +42,7 @@ class Section : public QWidget { public slots: - void toggled(bool collapsed); + void toggle(bool collapsed); public: From 1be698bf3ae0d7e8b5821d7c79bca27328ec52e4 Mon Sep 17 00:00:00 2001 From: michail-peterlis Date: Tue, 15 Oct 2019 12:55:31 +0200 Subject: [PATCH 3/3] fixed signal/slot connection --- Section.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Section.cpp b/Section.cpp index bd9b33e..57eed2c 100644 --- a/Section.cpp +++ b/Section.cpp @@ -62,7 +62,7 @@ Section::Section(const QString & title, const int animationDuration, QWidget* pa mainLayout->addWidget(contentArea, row, 0, 1, 3); setLayout(mainLayout); - connect(toggleButton, SIGNAL(toggled(bool)), this, SLOT(toggle(bool))); + connect(toggleButton, &QToolButton::toggled, this, &Section::toggle); }