Python Qtreewidget Button Insert Skipping Every Second Line
I have the following code where I use python and Qt to make a ui where I can see the data that is in a table. Works well, but I am trying to insert a button into the last column, w
Solution 1:
i = QTreeWidgetItem(self.treeWidget)
appends a new row, so you appended one for the data, and another for the widget, giving you alternating rows.
Also I'm not sure what
cw = QTreeWidget()
cw.setColumnCount(len(col))
is. It seems to be a fresh QTreeWidget that you are just discarding.
And [4][0]
is the weirdest way of writing 4
that I have seen.
Anyway, here is your main for loop fixed:
forrowinrange(len(table)):
# appends newrowto self.treeWidget
rowItem = QTreeWidgetItem(self.treeWidget)
forcolumninrange(len(table[item])):
if column!=4:
rowItem.setText(column, str(table[row][column]))
else:
button = QPushButton("push me " + str(value), self.treeWidget)
self.treeWidget.setItemWidget(rowItem, 4, button)
Post a Comment for "Python Qtreewidget Button Insert Skipping Every Second Line"