您可以使用scrollToItem方法来实现QTableWidget滚动到指定位置。这里是一个示例代码:

from PyQt5.QtWidgets import QApplication, QTableWidget, QTableWidgetItem, QWidget, QVBoxLayout
from PyQt5.QtCore import Qt

app = QApplication([])

table = QTableWidget()
table.setColumnCount(5)
table.setRowCount(5)

for row in range(5):
    for column in range(5):
        item = QTableWidgetItem(f'({row}, {column})')
        table.setItem(row, column, item)

widget = QWidget()
layout = QVBoxLayout(widget)
layout.addWidget(table)
widget.show()

# 滚动到指定位置 (2, 3)
table.scrollToItem(table.item(2, 3), QTableWidget.PositionAtCenter)

app.exec_()

在这个例子中,我们创建了一个QTableWidget并添加了一些QTableWidgetItem。然后,我们使用scrollToItem方法将第2行第3列的单元格滚动到可见区域的中心位置

QTableWidget 滚动到指定位置 23 我是添加的 cellWidget用不了scrollToItem

原文地址: http://www.cveoy.top/t/topic/i0XY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录