本文介绍了如何清除 pyqt QTableWidget?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想清除我的 QTableWidget.
I want to clear my QTableWidget.
首先,我在 qcombobox 中选择一个用户,然后单击 qpushbutton 并从数据库记录中填充它;当我选择其他用户并单击 qpushbutton 添加我尝试清除的数据时:
First of all I select a user in a qcombobox after that I click a qpushbutton and I populate it from database records; when I select other user and I click the qpushbutton to add data I try to clear with:
self.tableFriends.clear()
数据消失,但行仍然存在.
The data disappears but the rows remain.
我填充的代码是:
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
推荐答案
您需要单独删除行,例如:
You need to remove the rows individually, e.g:
while (self.tableFriends.rowCount() > 0)
{
self.tableFriends.removeRow(0);
}
你也可以试试:
tableFriends.setRowCount(0);
但这可能行不通,我已经有一段时间没有使用 Qt 了.
But that may not work, it's been a while since I've used Qt.
这篇关于如何清除 pyqt QTableWidget?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!