Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure to clear focus of any widgets contained by an Expander #74

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading