c++ - QTreeWidget可以跳转到特定行(由QTreeWidgetItem或列指定)吗?

标签 c++ qt qtreewidget

我使用setCurrentItem()来关注特定项目,但是QTreeWidget没有相应地跳转到特定项目。 QTreeWidget有什么函数可以做到这一点吗?

最佳答案

是的,您可以使用 scrollTo(const QModelIndex &index, ScrollHinthint = EnsureVisible) 函数 ( documentation link )。

index 参数是您要显示的项目的索引 hint 参数指定操作后项目应位于的位置(例如顶部、中间等)。

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

关于c++ - QTreeWidget可以跳转到特定行(由QTreeWidgetItem或列指定)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41629759/

相关文章:

c++ - 如果使用嵌套命名空间,如何转发声明 C++ 结构?

c++ - 使用数组作为 "goto"标签

c++ - 对 `qInitResources_systray()' 的 undefined reference

c++ - Qt多键组合事件

python - 跟踪 QTreeWidget 中的更改

python - 如何从元组填充 QTreeWidget?

c++ - boost 定时器限制

python - C++ 的 SWIG 包装问题 --> python

qt - 当我们不在 Qt 4.8x 中子类化 QThread 时,必须如何使用 QEventLoop?

c++ - 是否可以在 QTreeWidgetItem 上禁用浅蓝色鼠标突出显示?