From dc5e8aa81c7083659e2ec3090489f34072ebc383 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 28 May 2021 13:03:34 +0200 Subject: QAbstractItemView: don't toggle extended selection on Ctrl+Press In ExtendedSelection mode, a Ctrl+Press might be both the start of a selection toggle, or the start of a Ctrl+Drag operation. If we already toggle on the press, then it's impossible to drag the existing selection while the Control key is pressed. Ignore Ctrl+Press events and let the corresponding release event toggle the selection. Adjust the relevant test cases accordingly. The QItemDelegate test case used a click+control event incorrectly, such an event doesn't change the clicked state and should not be eaten, and now it does change the selection, so fix the test. Task-number: QTBUG-59888 Change-Id: Ia76126e31c28bc97d3e93e54965bdb1d0b8ac6a4 Reviewed-by: Qt CI Bot Reviewed-by: Lars Knoll --- .../widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'tests/auto/widgets/itemviews/qitemdelegate') diff --git a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp index 25212373a4..8d68ca7ac9 100644 --- a/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/widgets/itemviews/qitemdelegate/tst_qitemdelegate.cpp @@ -1394,6 +1394,7 @@ void tst_QItemDelegate::QTBUG4435_keepSelectionOnCheck() } QTableView view; view.setModel(&model); + view.setSelectionMode(QAbstractItemView::MultiSelection); view.setItemDelegate(new TestItemDelegate(&view)); view.show(); view.selectAll(); @@ -1404,11 +1405,16 @@ void tst_QItemDelegate::QTBUG4435_keepSelectionOnCheck() option.features = QStyleOptionViewItem::HasDisplay | QStyleOptionViewItem::HasCheckIndicator; option.checkState = Qt::CheckState(model.index(0, 0).data(Qt::CheckStateRole).toInt()); const int checkMargin = qApp->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1; - QPoint pos = qApp->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &option, 0).center() - + QPoint(checkMargin, 0); - QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, pos); - QTRY_VERIFY(view.selectionModel()->isColumnSelected(0, QModelIndex())); + QRect checkRect = qApp->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &option, 0); + checkRect.translate(checkMargin, 0); + // click into the check mark checks, but doesn't change selection + QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, checkRect.center()); QCOMPARE(model.item(0)->checkState(), Qt::Checked); + QTRY_VERIFY(view.selectionModel()->isColumnSelected(0, QModelIndex())); + // click outside the check mark doesn't check, and changes selection + QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, + checkRect.center() + QPoint(checkRect.width(), 0)); + QTRY_VERIFY(!view.selectionModel()->isColumnSelected(0, QModelIndex())); } void tst_QItemDelegate::comboBox() -- cgit v1.2.3