简体   繁体   中英

Can QTreeWidget jump to a specific line(specified by QTreeWidgetItem or column)?

I use setCurrentItem() to focus on a specific item,but the QTreeWidget does not jump to the specific item correspondingly. Are there any function of QTreeWidget can do this?

Yes, you can use the scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) function ( documentation link ).

The index parameter is the index of the item that you want to bring into view The hint parameter specifies where the item should be located after the operation (eg on top, in the middle, etc).

QTreeWidget w;
w.setCurrentItem(<your item>);
w.scrollTo(w.indexFromItem(<your item>)); // or w.scrollTo(w.currentIndex())

您可以使用 scrollToItem() :链接到 Qt 文档: https : //doc.qt.io/qt-5/qtreewidget.html#scrollToItem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM