summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2023-09-06 15:42:39 +0200
committerAxel Spoerl <axel.spoerl@qt.io>2023-09-11 13:26:56 +0000
commitedc984db384311e25a0afe4902585bd97e4ebcd1 (patch)
tree7f8a3656750562f21d63c529a62060cf5ec2e41b /tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp
parent36c2a9c51435739b51df7f95d1589bed7db7bcd7 (diff)
QDialogButtonBox: Manage hide and show of standard buttons
0b421fa58b9a73d657bf17834788fd1175c4767e ensured a correct focus chain, when buttons in a QDialogButtonBox were hidden. The implementation did not check, if a hidden button was added via setStandardButtons(). In consequence, it was removed from the standardButtonHash and never added again. QDialogButtonBox::button() returned nullptr for a standard button, once it had been hidden. That introduced a regression. This follow-up patch makes sure, a standard button is not removed from standardButtonHash, when hidden. By no longer removing it from standardButtonHash, it makes showQDialogButtonBox::button() always return the pointer to the standard button, even if it is hidden. The function handleButtonDestroyed() used the argument QDialogButtonBoxPrivate::RemoveRule::KeepConnections, in order to leave signal/slot connections untouched. It expected the the destroyed button to be removed from standardButtonHash. In order to retain that functionality, the enum class RemoveRule is renamed to RemoveReason, and one value was added. QDialogButtonBoxPrivate now handles all necessary cases of removing a button: ManualRemove (previously Disconnect): - remove button from roles - remove button from standardButtonHash - disconnect all signals LeaveEvent (previously KeepConnections): - remove button from roles - do not remove button form standardButtonHash - do not disconnect signals Destroyed (new): - remove button from roles - remove button from standardButtonHash - do not disconnect signals (QObject will do that) An autotest is added to tst_QDialogButtonBox. Task-number: QTBUG-114377 Pick-to: 6.6 6.5 Change-Id: Ib28625d44fa89c3d06f181f64875c2e456cebbfa Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp')
-rw-r--r--tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp b/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp
index b3f26e5dd8..3f5ffa687b 100644
--- a/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp
+++ b/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp
@@ -55,6 +55,7 @@ private slots:
#ifdef QT_BUILD_INTERNAL
void hideAndShowButton();
#endif
+ void hideAndShowStandardButton();
void buttonRole_data();
void buttonRole();
void setStandardButtons_data();
@@ -426,6 +427,22 @@ void tst_QDialogButtonBox::hideAndShowButton()
}
#endif
+void tst_QDialogButtonBox::hideAndShowStandardButton()
+{
+ QDialogButtonBox buttonBox;
+ buttonBox.setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+ buttonBox.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&buttonBox));
+ auto *button = buttonBox.button(QDialogButtonBox::Cancel);
+ QVERIFY(button);
+ button->hide();
+ QVERIFY(QTest::qWaitFor([button](){ return !button->isVisible(); }));
+ QCOMPARE(button, buttonBox.button(QDialogButtonBox::Cancel));
+ button->show();
+ QVERIFY(QTest::qWaitForWindowExposed(button));
+ QCOMPARE(button, buttonBox.button(QDialogButtonBox::Cancel));
+}
+
void tst_QDialogButtonBox::testDelete()
{
QDialogButtonBox buttonBox;