From df819cfe17f6dfd089096063524932fc4975804f Mon Sep 17 00:00:00 2001 From: Markku Heikkila Date: Fri, 11 Nov 2011 14:35:23 +0100 Subject: Fixed wrong QGroupBox check state Handle mouserelease only if mouse is pressed in QGroupBox. Task-number: QTBUG-19170 Reviewed-by: Friedemann Kleint --- src/gui/widgets/qgroupbox.cpp | 4 ++++ tests/auto/qgroupbox/tst_qgroupbox.cpp | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/gui/widgets/qgroupbox.cpp b/src/gui/widgets/qgroupbox.cpp index 56fb2dd..db068cf 100644 --- a/src/gui/widgets/qgroupbox.cpp +++ b/src/gui/widgets/qgroupbox.cpp @@ -733,6 +733,10 @@ void QGroupBox::mouseReleaseEvent(QMouseEvent *event) } Q_D(QGroupBox); + if (!d->overCheckBox) { + event->ignore(); + return; + } QStyleOptionGroupBox box; initStyleOption(&box); QStyle::SubControl released = style()->hitTestComplexControl(QStyle::CC_GroupBox, &box, diff --git a/tests/auto/qgroupbox/tst_qgroupbox.cpp b/tests/auto/qgroupbox/tst_qgroupbox.cpp index f1388bc..f3d26ef 100644 --- a/tests/auto/qgroupbox/tst_qgroupbox.cpp +++ b/tests/auto/qgroupbox/tst_qgroupbox.cpp @@ -83,6 +83,7 @@ private slots: void toggledVsClicked(); void childrenAreDisabled(); void propagateFocus(); + void task_QTBUG_19170_ignoreMouseReleseEvent(); private: bool checked; @@ -473,5 +474,27 @@ void tst_QGroupBox::propagateFocus() QTRY_COMPARE(qApp->focusWidget(), static_cast(&lineEdit)); } +void tst_QGroupBox::task_QTBUG_19170_ignoreMouseReleseEvent() +{ + QGroupBox box; + box.setCheckable(true); + box.setChecked(false); + box.setTitle("This is a test for QTBUG-19170"); + box.show(); + + QStyleOptionGroupBox option; + option.initFrom(&box); + option.subControls = QStyle::SubControls(QStyle::SC_All); + QRect rect = box.style()->subControlRect(QStyle::CC_GroupBox, &option, + QStyle::SC_GroupBoxCheckBox, &box); + + QTest::mouseClick(&box, Qt::LeftButton, 0, rect.center()); + QCOMPARE(box.isChecked(), true); + + box.setChecked(false); + QTest::mouseRelease(&box, Qt::LeftButton, 0, rect.center()); + QCOMPARE(box.isChecked(), false); +} + QTEST_MAIN(tst_QGroupBox) #include "tst_qgroupbox.moc" -- cgit v0.12