Home  >  Q&A  >  body text

python - pyqt的tablewidget,现在想实现一个快速定位到某一行并显示的功能

因为现在用pyqt来显示tablewidget表格的行数很多,用鼠标滚轮要很久,想做一个输入行号就直接定位过去并显示,比如输入9999,就直接显示第9999行,相当于鼠标滚轮到了第9999行。
查了一下qt的官方手册,貌似没有类似的接口?

PHP中文网PHP中文网2742 days ago989

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:18:27

    item=self.tableWidget.findItems(text, QtCore.Qt.MatchExactly)#遍历表查找对应的item
    row=item[0].row()                                            #获取其行号
    self.tableWidget.verticalScrollBar().setSliderPosition(row)  #滚轮定位过去,搞定

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 10:18:27

    It is not recommended to display too much data. You can change the idea and paginate the table. Line 9999 can be displayed directly to the page. This way the table takes up less memory and is easy to view

    reply
    0
  • Cancelreply