From fce83bd9f84883f93829e6ca9eacf098b018a02d Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 22 Mar 2016 11:59:56 +0100 Subject: QAbstractItemView: trigger handlers (and redraw) when changing selection model The most visible problem is that changing selection model didn't update() the view, resulting in the old selection/current item still being drawn. In general trigger the handlers for when the selection/current item changes. Change-Id: Ib3b2ad70412e6a21a182d4c173e617710bcc630d Task-number: QTBUG-50535 Reviewed-by: Stephen Kelly --- src/widgets/itemviews/qabstractitemview.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index a126fef65e..251b09ce7d 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -765,7 +765,13 @@ void QAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel) return; } + QItemSelection oldSelection; + QModelIndex oldCurrentIndex; + if (d->selectionModel) { + oldSelection = d->selectionModel->selection(); + oldCurrentIndex = d->selectionModel->currentIndex(); + disconnect(d->selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection))); disconnect(d->selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), @@ -779,6 +785,9 @@ void QAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel) this, SLOT(selectionChanged(QItemSelection,QItemSelection))); connect(d->selectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex))); + + selectionChanged(d->selectionModel->selection(), oldSelection); + currentChanged(d->selectionModel->currentIndex(), oldCurrentIndex); } } -- cgit v1.2.3