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

Backport changes to v4.3.x branch #15150

Merged
merged 8 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Don't close tags menu when toggling items (#15098)
The issue was resolved by using QAction::toggled signal instead of
QAction::triggered. In QT 5.15+ the latter signal causes a QMenu
to close, whereas the former does not. Closes #13492.
  • Loading branch information
tgregerson authored and glassez committed Jul 1, 2021
commit c06d6eaa77559883bf965318de2778b63c17dba8
4 changes: 2 additions & 2 deletions src/gui/transferlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,14 +1008,14 @@ void TransferListWidget::displayListMenu(const QPoint &)
for (const QString &tag : asConst(tags))
{
auto *action = new TriStateAction(tag, tagsMenu);
action->setCloseOnTriggered(false);
action->setCloseOnInteraction(false);

const Qt::CheckState initialState = tagsInAll.contains(tag) ? Qt::Checked
: tagsInAny.contains(tag) ? Qt::PartiallyChecked
: Qt::Unchecked;
action->setCheckState(initialState);

connect(action, &QAction::triggered, this, [this, tag](const bool checked)
connect(action, &QAction::toggled, this, [this, tag](const bool checked)
{
if (checked)
addSelectionTag(tag);
Expand Down
7 changes: 3 additions & 4 deletions src/gui/tristateaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ TriStateAction::TriStateAction(const QString &text, QWidget *parent)
m_triStateWidget->setCheckState(checked ? Qt::Checked : Qt::Unchecked);
});

connect(m_triStateWidget, &TriStateWidget::triggered, this, &QAction::setChecked);
connect(m_triStateWidget, &TriStateWidget::triggered, this, &QAction::triggered);
connect(m_triStateWidget, &TriStateWidget::triggered, this, &QAction::toggled);
setDefaultWidget(m_triStateWidget);
}

Expand All @@ -56,7 +55,7 @@ void TriStateAction::setCheckState(const Qt::CheckState checkState)
m_triStateWidget->setCheckState(checkState);
}

void TriStateAction::setCloseOnTriggered(const bool enabled)
void TriStateAction::setCloseOnInteraction(const bool enabled)
{
m_triStateWidget->setCloseOnTriggered(enabled);
m_triStateWidget->setCloseOnInteraction(enabled);
}
9 changes: 7 additions & 2 deletions src/gui/tristateaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TriStateWidget;

// TriStateWidget is responsible for checkbox state (tri-state) and paint events while
// TriStateAction will keep in sync with it. This allows connecting with the usual
// QAction::triggered slot.
// QAction::triggered or QAction::toggled slots.
class TriStateAction : public QWidgetAction
{
public:
Expand All @@ -46,7 +46,12 @@ class TriStateAction : public QWidgetAction
// should use this function instead of QAction::setChecked(bool)
void setCheckState(Qt::CheckState checkState);

void setCloseOnTriggered(bool enabled);
// When set to 'true' toggling the checkbox will emit a signal on
// QAction::triggered. When placed in a QMenu, this causes the menu to close.
// When set to 'false' emits a signal on QAction::toggled instead, leaving the
// menu open.
// Default value: 'true'.
void setCloseOnInteraction(bool enabled);

private:
TriStateWidget *m_triStateWidget;
Expand Down
12 changes: 6 additions & 6 deletions src/gui/tristatewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

TriStateWidget::TriStateWidget(const QString &text, QWidget *parent)
: QWidget {parent}
, m_closeOnTriggered {true}
, m_closeOnInteraction {true}
, m_checkState {Qt::Unchecked}
, m_text {text}
{
Expand All @@ -51,9 +51,9 @@ void TriStateWidget::setCheckState(const Qt::CheckState checkState)
m_checkState = checkState;
}

void TriStateWidget::setCloseOnTriggered(const bool enabled)
void TriStateWidget::setCloseOnInteraction(const bool enabled)
{
m_closeOnTriggered = enabled;
m_closeOnInteraction = enabled;
}

QSize TriStateWidget::minimumSizeHint() const
Expand Down Expand Up @@ -104,15 +104,15 @@ void TriStateWidget::mouseReleaseEvent(QMouseEvent *event)
{
toggleCheckState();

if (m_closeOnTriggered)
if (m_closeOnInteraction)
{
// parent `triggered` signal will be emitted
QWidget::mouseReleaseEvent(event);
}
else
{
update();
// need to emit parent `triggered` signal manually
// need to emit `triggered` signal manually
emit triggered(m_checkState == Qt::Checked);
}
}
Expand All @@ -124,7 +124,7 @@ void TriStateWidget::keyPressEvent(QKeyEvent *event)
{
toggleCheckState();

if (!m_closeOnTriggered)
if (!m_closeOnInteraction)
{
update();
// need to emit parent `triggered` signal manually
Expand Down
4 changes: 2 additions & 2 deletions src/gui/tristatewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TriStateWidget final : public QWidget
TriStateWidget(const QString &text, QWidget *parent);

void setCheckState(Qt::CheckState checkState);
void setCloseOnTriggered(bool enabled);
void setCloseOnInteraction(bool enabled);

signals:
void triggered(bool checked) const;
Expand All @@ -55,7 +55,7 @@ class TriStateWidget final : public QWidget

void toggleCheckState();

bool m_closeOnTriggered;
bool m_closeOnInteraction;
Qt::CheckState m_checkState;
const QString m_text;
};