Skip to content

Commit

Permalink
Rework implementation as suggested by oclero
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieter-Dewachter committed Jan 17, 2025
1 parent 5cb32e8 commit fa71b78
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/include/oclero/qlementine/utils/WidgetUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ qreal getDpi(const QWidget* widget);

QWindow* getWindow(const QWidget* widget);

void clearFocus(QWidget* widget, bool recursive);

template<class T>
T* findFirstParentOfType(QWidget* child) {
auto* parent = child;
Expand Down
13 changes: 13 additions & 0 deletions lib/src/utils/WidgetUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QWidget*>();
for (auto* child : children) {
clearFocus(child, recursive);
}
}
}
}
} // namespace oclero::qlementine
2 changes: 2 additions & 0 deletions lib/src/widgets/Expander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: MIT

#include <oclero/qlementine/widgets/Expander.hpp>
#include <oclero/qlementine/utils/WidgetUtils.hpp>

#include <QStyle>
#include <QEvent>
Expand Down Expand Up @@ -106,6 +107,7 @@ void Expander::setExpanded(bool expanded) {
if (_expanded) {
emit aboutToExpand();
} else {
oclero::qlementine::clearFocus(this, true);
emit aboutToShrink();
}

Expand Down

0 comments on commit fa71b78

Please sign in to comment.