Python QTableWidget 定位单元格到可视区域 - 解决 scrollContentsBy 无法定位问题
"""\ndef dingwei(self, row, column):\n\t"""\n\t"""定位单元格到可视区域\n\t"""\n\titem = self.tabw_jiankong.cellWidget(row, column)\n\tscroll_position = item.geometry().topLeft()\n\tself.tabw_jiankong.scrollContentsBy(scroll_position.x(), scroll_position.y())\n"""\n这个函数运行后并不能定位 应该怎么改\n\n根据您提供的代码,我看到您想要使用scrollContentsBy函数来滚动到指定的位置,但是这种方式不会产生预期的结果。\n\n如果您想要将某个单元格滚动到可见区域,您可以尝试使用scrollToItem函数来实现。修改您的代码如下:\n\npython\ndef dingwei(self, row, column):\n\titem = self.tabw_jiankong.item(row, column)\n\tself.tabw_jiankong.scrollToItem(item, QtWidgets.QAbstractItemView.PositionAtCenter)\n\n\n在这个修改后的代码中,我们首先通过item方法获取到指定单元格的QTableWidgetItem对象。然后,我们使用scrollToItem函数来将该单元格滚动到可见区域,PositionAtCenter参数表示将该单元格置于可见区域的中心位置。\n\n希望这个修改能够帮助到您!如果您还有其他问题,请随时提问。\n
原文地址: https://www.cveoy.top/t/topic/nWvL 著作权归作者所有。请勿转载和采集!