How can I clear pyqt QTableWidget?

I want to clear my QTableWidget.

First of all, I select the user in qcombobox after that, I press the qpushbutton button, and I populate it from the database entries; when I select another user and I press the qpush button to add the data that I am trying to clear with:

self.tableFriends.clear()

The data disappears, but the rows remain.

The code I fill out is:

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
+4
source share
1 answer

You need to delete the lines separately, for example:

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

You can also try:

tableFriends.setRowCount(0);

But this may not work, it has been a while since I used Qt.

+8
source

All Articles