From 971b8413f27f6e317e9e37f518fcc1e6b9eed978 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 9 Mar 2015 14:29:05 +0100 Subject: QAbstractButton: emit released on focus out or disable When pressing a button with the mouse and then moving the focus away, the internal and visual state of the button would get updated, but the released signal would not be emitted. The same goes for disabling the button, although in 99% of the cases, disabling the button will also move the focus, so the first case already takes care of emitting the signal. Task-number: QTBUG-42775 Change-Id: Ib6ba8e0a75f0349b66d1e799b02bd8498db85022 Reviewed-by: Gabriel de Dietrich --- .../widgets/qpushbutton/tst_qpushbutton.cpp | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp') diff --git a/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp b/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp index c53a7cc5ca..4fd8b99acf 100644 --- a/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp +++ b/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp @@ -76,6 +76,7 @@ private slots: void sizeHint_data(); void sizeHint(); void taskQTBUG_20191_shortcutWithKeypadModifer(); + void emitReleasedAfterChange(); protected slots: void resetCounters(); @@ -663,5 +664,36 @@ void tst_QPushButton::taskQTBUG_20191_shortcutWithKeypadModifer() QCOMPARE(spy2.count(), 1); } +void tst_QPushButton::emitReleasedAfterChange() +{ + QPushButton *button1 = new QPushButton("A"); + QPushButton *button2 = new QPushButton("B"); + QVBoxLayout *layout = new QVBoxLayout(); + layout->addWidget(button1); + layout->addWidget(button2); + QDialog dialog; + dialog.setLayout(layout); + dialog.show(); + QTest::qWaitForWindowExposed(&dialog); + QApplication::setActiveWindow(&dialog); + button1->setFocus(); + + QSignalSpy spy(button1, SIGNAL(released())); + QTest::mousePress(button1, Qt::LeftButton); + QVERIFY(button1->isDown()); + QTest::keyClick(&dialog, Qt::Key_Tab); + QVERIFY(!button1->isDown()); + QCOMPARE(spy.count(), 1); + spy.clear(); + + QCOMPARE(spy.count(), 0); + button1->setFocus(); + QTest::mousePress(button1, Qt::LeftButton); + QVERIFY(button1->isDown()); + button1->setEnabled(false); + QVERIFY(!button1->isDown()); + QCOMPARE(spy.count(), 1); +} + QTEST_MAIN(tst_QPushButton) #include "tst_qpushbutton.moc" -- cgit v1.2.3