QTableView - 滚动时更改选择
我有一个 QTableView。我希望滚动时移动选择 - 因此光标始终可见。
有 QTableView.selectRow(rowNo)
,但是您有建议吗在哪里调用这个?
理想情况下,我希望在滚动所选行时位于中心。
I have a QTableView. I want the selection to be moved when i scroll - so the cursor would be always visible.
There is QTableView.selectRow(rowNo)
, but do you have a suggestion where to call this?
Ideally i would like upon scrolling the selected row to be in the center.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用方法 .indexAt(viewport().pos())。您可能需要稍微调整一下位置。即按标题大小移动它。当你有索引时,你可以简单地调用 .row() 方法
You could use method .indexAt(viewport().pos()). You may need to fix position a little bit. i.e. move it by headers size. When you have index you can simply call .row() method
我这样做了(PyQt4):
在初始化时,我连接到滚动条事件:
然后在处理程序中:
I did it like this (PyQt4):
Upon init i connect to scrollbar event:
Then in the handler: