summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFrank Reininghaus <frank78ac@googlemail.com>2016-05-18 19:25:36 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2016-10-07 10:38:58 +0000
commit5cc0d92c2493aea8397a51eea80167abdd6a1fa6 (patch)
tree3232507f9850e3431eb5c645d31edb4fb0f66954 /src
parentc6f5e4b47c3f27c80768e735bb4109a8dc83d2e5 (diff)
QAbstractItemView: use only a 1x1 QRect for selecting on mouse press
Before commit f1e90768095be37419ba4bf3c69ec5c860bdbcb6, mousePressEvent called the virtual method setSelection(const QRect&, SelectionFlags) with the 1x1 rectangle which contains only the clicked QPoint, unless the SelectionFlag "Current" was set because Shift was pressed during the mouse press. Since that commit, the behavior has been changed such that the rectangle is the one that is spanned by the center of the clicked item and the clicked pixel. In theory, the result should be the same (i.e., only the clicked item should be selected), but * the code path in QListView::setSelection for 1x1 QRects is more efficient, and * using a larger QRect can cause problems with custom views, see the comments in QTBUG-18009 This commit ensures that the 1x1 QRect is used again, unless the SelectionFlag "Current" is used. Change-Id: I70dd70c083c20a3af6cd6095aa89a489756b505f Task-number: QTBUG-18009 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/itemviews/qabstractitemview.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp
index d36431c716..4dd8ad0215 100644
--- a/src/widgets/itemviews/qabstractitemview.cpp
+++ b/src/widgets/itemviews/qabstractitemview.cpp
@@ -1735,13 +1735,18 @@ void QAbstractItemView::mousePressEvent(QMouseEvent *event)
d->autoScroll = false;
d->selectionModel->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
d->autoScroll = autoScroll;
- QRect rect(visualRect(d->currentSelectionStartIndex).center(), pos);
if (command.testFlag(QItemSelectionModel::Toggle)) {
command &= ~QItemSelectionModel::Toggle;
d->ctrlDragSelectionFlag = d->selectionModel->isSelected(index) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select;
command |= d->ctrlDragSelectionFlag;
}
- setSelection(rect, command);
+
+ if ((command & QItemSelectionModel::Current) == 0) {
+ setSelection(QRect(pos, QSize(1, 1)), command);
+ } else {
+ QRect rect(visualRect(d->currentSelectionStartIndex).center(), pos);
+ setSelection(rect, command);
+ }
// signal handlers may change the model
emit pressed(index);