Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.15.2, 6.1.3
-
None
Description
QTreeView::scrollTo uses the scroll bar's pageStep as count of how many items are visible in the viewport. It uses that and the index of the first visible item to check whether the item is already in view. The pageStep however is not dependent on the actually visible items in the view, but instead is calculated by taking as many items from the end of the model that would fit into the view.
The result is that if the end of the model has smaller items, pageStep is bigger than it should be, because more of the smaller items fit into view. Thus it thinks the target item fits, and does not scroll, even if the item is partially or completely out of view.
Here a reproducer, just press arrow down on the keyboard until the selected item is no longer visible:
#include <QApplication> #include <QTreeView> #include <QStandardItemModel> #include <QStandardItem> int main(int argc, char *argv[]) { QApplication app(argc, argv); QTreeView tv; QStandardItemModel sim; // Add 20 items with 20px height and 20 items with 10px height for(int i = 0; i < 40; ++i) { auto *item = new QStandardItem(QStringLiteral("Item %1").arg(i)); item->setSizeHint(QSize(100, i < 20 ? 20 : 10)); sim.appendRow(item); } tv.setModel(&sim); tv.show(); return app.exec(); }
A workaround is to use QAbstractItemView::ScrollPerPixel instead of QAbstractItemView::ScrollPerItem.
Attachments
Gerrit Reviews
For Gerrit Dashboard: QTBUG-96980 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
376569,4 | Fix QTreeView::scrollTo not always scrolling when necessary | dev | qt/qtbase | Status: NEW | -1 | 0 |