summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp')
-rw-r--r--tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp51
1 files changed, 49 insertions, 2 deletions
diff --git a/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp b/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp
index 8acbfeb6cf..73360ae21d 100644
--- a/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp
+++ b/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -15,6 +15,7 @@
#include <QGridLayout>
#include <QStyleFactory>
#include <QTabWidget>
+#include <QStyleOption>
#include <private/qguiapplication_p.h>
#include <qpa/qplatformtheme.h>
@@ -54,6 +55,7 @@ private slots:
void hitButton();
void iconOnlyStyleSheet();
void mousePressAndMove();
+ void reactToMenuClosed();
protected slots:
void resetCounters();
@@ -337,7 +339,6 @@ void tst_QPushButton::setAccel()
// The shortcut will not be activated unless the button is in a active
// window and has focus
- QApplicationPrivate::setActiveWindow(testWidget);
testWidget->setFocus();
QVERIFY(QTest::qWaitForWindowActive(testWidget));
QTest::keyClick(testWidget, 'A', Qt::AltModifier);
@@ -760,5 +761,51 @@ void tst_QPushButton::mousePressAndMove()
QCOMPARE(releaseSpy.size(), 1);
}
+/*
+ Test checking that a QPushButton with a QMenu has a sunken style only
+ when the menu is open
+ QTBUG-120976
+*/
+void tst_QPushButton::reactToMenuClosed()
+{
+ // create a subclass of QPushButton to expose the initStyleOption method
+ class PushButton : public QPushButton {
+ public:
+ virtual void initStyleOption(QStyleOptionButton *option) const override
+ {
+ QPushButton::initStyleOption(option);
+ }
+ };
+
+ PushButton button;
+ QStyleOptionButton opt;
+ QMenu menu;
+
+ // add a menu to the button
+ menu.addAction(tr("string"));
+ button.setMenu(&menu);
+
+ // give the button a size and show it
+ button.setGeometry(0, 0, 50, 50);
+ button.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&button));
+
+ // click the button to open the menu
+ QTest::mouseClick(&button, Qt::LeftButton);
+
+ // check the menu is visible and the button style is sunken
+ QTRY_VERIFY(menu.isVisible());
+ button.initStyleOption(&opt);
+ QVERIFY(opt.state.testFlag(QStyle::StateFlag::State_Sunken));
+
+ // close the menu
+ menu.close();
+
+ // check the menu isn't visible and the style isn't sunken
+ QTRY_VERIFY(!menu.isVisible());
+ button.initStyleOption(&opt);
+ QVERIFY(!opt.state.testFlag(QStyle::StateFlag::State_Sunken));
+}
+
QTEST_MAIN(tst_QPushButton)
#include "tst_qpushbutton.moc"