QTreeView: sync keyboard search behavior with other itemviews
QTreeView has a special implementation of keyboardSearch() which is not consistent to the base implementation regarding the selection behavior: - currentSelectionStartIndex is not set which results in a wrong mouse selection behavior afterwards - only the current index is set but not the current selection Sync the behavior by calling setCurrentIndex() directly in QTreeView too. One problem remains with this patch - the key handling is still different between QAbstractItemView and QTreeView for repeating key presses. Task-number: QTBUG-18862 Change-Id: Ife79d146cf16d6ecbf9f86540777dae15aa1ffb0 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>bb10
parent
d0c159c8e3
commit
7fafeb4a34
|
|
@ -1088,15 +1088,8 @@ void QTreeView::keyboardSearch(const QString &search)
|
|||
if (start.column() > 0)
|
||||
index = index.sibling(index.row(), start.column());
|
||||
|
||||
if (index.isValid()) {
|
||||
QItemSelectionModel::SelectionFlags flags = (d->selectionMode == SingleSelection
|
||||
? QItemSelectionModel::SelectionFlags(
|
||||
QItemSelectionModel::ClearAndSelect
|
||||
|d->selectionBehaviorFlags())
|
||||
: QItemSelectionModel::SelectionFlags(
|
||||
QItemSelectionModel::NoUpdate));
|
||||
selectionModel()->setCurrentIndex(index, flags);
|
||||
}
|
||||
if (index.isValid())
|
||||
setCurrentIndex(index);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -2435,6 +2435,8 @@ void tst_QTreeView::selection()
|
|||
for (int i = 0;i < 10; ++i)
|
||||
m.setData(m.index(i, 0), i);
|
||||
treeView.setModel(&m);
|
||||
treeView.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&treeView));
|
||||
|
||||
treeView.setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
treeView.setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
|
|
@ -2446,6 +2448,13 @@ void tst_QTreeView::selection()
|
|||
|
||||
QTest::mousePress(treeView.viewport(), Qt::LeftButton, 0, treeView.visualRect(m.index(1, 0)).center());
|
||||
QTest::keyPress(treeView.viewport(), Qt::Key_Down);
|
||||
auto selectedRows = treeView.selectionModel()->selectedRows();
|
||||
QCOMPARE(selectedRows.size(), 1);
|
||||
QCOMPARE(selectedRows.first(), m.index(2, 0, QModelIndex()));
|
||||
QTest::keyPress(treeView.viewport(), Qt::Key_5);
|
||||
selectedRows = treeView.selectionModel()->selectedRows();
|
||||
QCOMPARE(selectedRows.size(), 1);
|
||||
QCOMPARE(selectedRows.first(), m.index(5, 0, QModelIndex()));
|
||||
}
|
||||
|
||||
//From task 151686 QTreeView ExtendedSelection selects hidden rows
|
||||
|
|
|
|||
Loading…
Reference in New Issue