Fixed wrong QGroupBox check state

Handle mouserelease only if mouse is pressed in QGroupBox.

Task-number: QTBUG-19170

Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
(cherry picked from commit df819cfe17f6dfd089096063524932fc4975804f)
Change-Id: Idf819cfe17f6dfd089096063524932fc4975804f
This commit is contained in:
Markku Heikkila 2011-11-11 14:35:23 +01:00 committed by Qt by Nokia
parent ad20e965d7
commit d7695e82ac
2 changed files with 27 additions and 0 deletions

View File

@ -734,6 +734,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,

View File

@ -81,6 +81,7 @@ private slots:
void toggledVsClicked();
void childrenAreDisabled();
void propagateFocus();
void task_QTBUG_19170_ignoreMouseReleseEvent();
private:
bool checked;
@ -471,5 +472,27 @@ void tst_QGroupBox::propagateFocus()
QTRY_COMPARE(qApp->focusWidget(), static_cast<QWidget*>(&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"