1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 07:18:08 +00:00

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.
This commit is contained in:
tgregerson 2021-06-16 09:57:56 -05:00 committed by GitHub
parent 2bd2490539
commit e74ad86f14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 16 deletions

View File

@ -1009,13 +1009,13 @@ 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);

View File

@ -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);
}
@ -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);
}

View File

@ -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:
@ -46,7 +46,12 @@ public:
// 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;

View File

@ -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}
{
@ -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
@ -104,7 +104,7 @@ void TriStateWidget::mouseReleaseEvent(QMouseEvent *event)
{
toggleCheckState();
if (m_closeOnTriggered)
if (m_closeOnInteraction)
{
// parent `triggered` signal will be emitted
QWidget::mouseReleaseEvent(event);
@ -112,7 +112,7 @@ void TriStateWidget::mouseReleaseEvent(QMouseEvent *event)
else
{
update();
// need to emit parent `triggered` signal manually
// need to emit `triggered` signal manually
emit triggered(m_checkState == Qt::Checked);
}
}
@ -124,7 +124,7 @@ void TriStateWidget::keyPressEvent(QKeyEvent *event)
{
toggleCheckState();
if (!m_closeOnTriggered)
if (!m_closeOnInteraction)
{
update();
// need to emit parent `triggered` signal manually

View File

@ -41,7 +41,7 @@ public:
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;
@ -55,7 +55,7 @@ private:
void toggleCheckState();
bool m_closeOnTriggered;
bool m_closeOnInteraction;
Qt::CheckState m_checkState;
const QString m_text;
};