gpt4 book ai didi

python-2.7 - 如何清除 pyqt QTableWidget?

转载 作者:行者123 更新时间:2023-12-04 13:38:35 24 4
gpt4 key购买 nike

我想清除我的 QTableWidget。

首先,我在 qcombobox 中选择一个用户,然后单击 qpushbutton 并从数据库记录中填充它;当我选择其他用户并单击 qpushbutton 添加我尝试清除的数据时:

self.tableFriends.clear()

数据消失,但行仍然存在。

我填充的代码是:
def getFriends(self):
id_us = self.cbUser.itemData(self.cbUser.currentIndex()).toPyObject()
rowIndex = 0
self.tableFriends.clear()
for row in self.SELECT_FRIENDS(id_us):
self.tableFriends.insertRow(rowIndex)
for column in range(0,3):
newItem = QtGui.QTableWidgetItem(str(row[column]).decode('utf-8'))
self.tableFriends.setItem(rowIndex,column,newItem)
rowIndex = rowIndex + 1

最佳答案

您需要单独删除行,例如:

while (self.tableFriends.rowCount() > 0)
{
self.tableFriends.removeRow(0);
}

你也可以试试:
tableFriends.setRowCount(0);

但这可能行不通,自从我使用 Qt 以来已经有一段时间了。

关于python-2.7 - 如何清除 pyqt QTableWidget?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29266452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com