diff --git a/lib/include/oclero/qlementine/utils/WidgetUtils.hpp b/lib/include/oclero/qlementine/utils/WidgetUtils.hpp index ae579b9..bc22c20 100644 --- a/lib/include/oclero/qlementine/utils/WidgetUtils.hpp +++ b/lib/include/oclero/qlementine/utils/WidgetUtils.hpp @@ -17,6 +17,8 @@ qreal getDpi(const QWidget* widget); QWindow* getWindow(const QWidget* widget); +void clearFocus(QWidget* widget, bool recursive); + template T* findFirstParentOfType(QWidget* child) { auto* parent = child; diff --git a/lib/src/utils/WidgetUtils.cpp b/lib/src/utils/WidgetUtils.cpp index 01bfa7d..80d0670 100644 --- a/lib/src/utils/WidgetUtils.cpp +++ b/lib/src/utils/WidgetUtils.cpp @@ -78,4 +78,17 @@ QWindow* getWindow(const QWidget* widget) { } return nullptr; } + +void clearFocus(QWidget* widget, bool recursive) { + if (widget) { + widget->clearFocus(); + + if (recursive) { + const auto children = widget->findChildren(); + for (auto* child : children) { + clearFocus(child, recursive); + } + } + } +} } // namespace oclero::qlementine diff --git a/lib/src/widgets/Expander.cpp b/lib/src/widgets/Expander.cpp index db6882b..2a0e18c 100644 --- a/lib/src/widgets/Expander.cpp +++ b/lib/src/widgets/Expander.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: MIT #include +#include #include #include @@ -106,6 +107,7 @@ void Expander::setExpanded(bool expanded) { if (_expanded) { emit aboutToExpand(); } else { + oclero::qlementine::clearFocus(this, true); emit aboutToShrink(); }