diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index 98afaa3b48..254e952b8c 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -294,10 +294,13 @@ QItemSelectionRange QItemSelectionRange::intersected(const QItemSelectionRange & static void indexesFromRange(const QItemSelectionRange &range, QModelIndexList &result) { if (range.isValid() && range.model()) { - const QModelIndex parent = range.parent(); - for (int column = range.left(); column <= range.right(); ++column) { - for (int row = range.top(); row <= range.bottom(); ++row) { - QModelIndex index = range.model()->index(row, column, parent); + const QModelIndex topLeft = range.topLeft(); + const int bottom = range.bottom(); + const int right = range.right(); + for (int row = topLeft.row(); row <= bottom; ++row) { + const QModelIndex columnLeader = topLeft.sibling(row, topLeft.column()); + for (int column = topLeft.column(); column <= right; ++column) { + QModelIndex index = columnLeader.sibling(row, column); Qt::ItemFlags flags = range.model()->flags(index); if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) result.append(index);