summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/itemviews/qtreeview.cpp7
-rw-r--r--tests/auto/qtreeview/tst_qtreeview.cpp22
2 files changed, 27 insertions, 2 deletions
diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp
index bf88a75..f25d648 100644
--- a/src/gui/itemviews/qtreeview.cpp
+++ b/src/gui/itemviews/qtreeview.cpp
@@ -2644,10 +2644,13 @@ void QTreeView::selectAll()
return;
SelectionMode mode = d->selectionMode;
d->executePostedLayout(); //make sure we lay out the items
- if (mode != SingleSelection && !d->viewItems.isEmpty())
- d->select(d->viewItems.first().index, d->viewItems.last().index,
+ if (mode != SingleSelection && !d->viewItems.isEmpty()) {
+ const QModelIndex &idx = d->viewItems.last().index;
+ QModelIndex lastItemIndex = idx.sibling(idx.row(), d->model->columnCount(idx.parent()) - 1);
+ d->select(d->viewItems.first().index, lastItemIndex,
QItemSelectionModel::ClearAndSelect
|QItemSelectionModel::Rows);
+ }
}
/*!
diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp
index 4fc6dd3..06bc93e 100644
--- a/tests/auto/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/qtreeview/tst_qtreeview.cpp
@@ -236,6 +236,7 @@ private slots:
void task248022_changeSelection();
void task245654_changeModelAndExpandAll();
void doubleClickedWithSpans();
+ void taskQTBUG_6450_selectAllWith1stColumnHidden();
};
class QtTestModel: public QAbstractItemModel
@@ -3678,5 +3679,26 @@ void tst_QTreeView::doubleClickedWithSpans()
QTRY_COMPARE(spy.count(), 2);
}
+void tst_QTreeView::taskQTBUG_6450_selectAllWith1stColumnHidden()
+{
+ QTreeWidget tree;
+ tree.setSelectionMode(QAbstractItemView::MultiSelection);
+ tree.setColumnCount(2);
+ QList<QTreeWidgetItem *> items;
+ const int nrRows = 10;
+ for (int i = 0; i < nrRows; ++i) {
+ items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i))));
+ items.last()->setText(1, QString("is an item"));
+ }
+ tree.insertTopLevelItems(0, items);
+
+ tree.hideColumn(0);
+ tree.selectAll();
+
+ QVERIFY(tree.selectionModel()->hasSelection());
+ for (int i = 0; i < nrRows; ++i)
+ QVERIFY(tree.selectionModel()->isRowSelected(i, QModelIndex()));
+}
+
QTEST_MAIN(tst_QTreeView)
#include "tst_qtreeview.moc"