Commit 0738ffa1 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Avoid keyboard focus for UI elements in the collapsed content area

Hide the content area when it is fully collapsed and make it visible
before starting the expand animation. This ensures that the children
of the content area do not receive the keyboard input focus when the
content area is collapsed.

GnuPG-bug-id: 6046
parent 9af5f1ea
......@@ -92,6 +92,7 @@ AnimatedExpander::AnimatedExpander(const QString &title, QWidget *parent):
// start out collapsed
contentArea.setMaximumHeight(0);
contentArea.setMinimumHeight(0);
contentArea.setVisible(false);
// let the entire widget grow and shrink with its content
toggleAnimation.addAnimation(new QPropertyAnimation(this, "minimumHeight"));
......@@ -106,10 +107,20 @@ AnimatedExpander::AnimatedExpander(const QString &title, QWidget *parent):
mainLayout.addWidget(&contentArea, row, 0, 1, 3);
setLayout(&mainLayout);
QObject::connect(&toggleButton, &QToolButton::clicked, [this](const bool checked) {
if (checked) {
// make the content visible when expanding starts
contentArea.setVisible(true);
}
toggleButton.setArrowType(checked ? Qt::ArrowType::DownArrow : Qt::ArrowType::RightArrow);
toggleAnimation.setDirection(checked ? QAbstractAnimation::Forward : QAbstractAnimation::Backward);
toggleAnimation.start();
});
connect(&toggleAnimation, &QAbstractAnimation::finished, [this]() {
// hide the content area when it is fully collapsed
if (!toggleButton.isChecked()) {
contentArea.setVisible(false);
}
});
}
void AnimatedExpander::setContentLayout(QLayout *contentLayout)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment