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, which is just a column that I have created as a "placeholder" for the button. (I don't use the data in that column)
But my problem is that I get the button inserted, but only into every second line. The it goes on inserting every second line even when the rows from the table have stopped.
col = self.dbu.GetColumn_names()
table = self.dbu.GetTable()
for c in range (len(col)):
self.treeWidget.headerItem().setText(c, col[c])
self.treeWidget.clear()
cw = QTreeWidget()
cw.setColumnCount(len(col))
for item in range(len(table)):
QTreeWidgetItem(self.treeWidget)
for value in range(len(table[item])):
if value != 4:
self.treeWidget.topLevelItem(item).setText(value, str(table[item][value]))
else:
i = QTreeWidgetItem(self.treeWidget)
b = QPushButton("push me " + str(value), cw)
self.treeWidget.setItemWidget(i, [4][0], b)
I copied and pasted the code from everywhere and have tried a hundred things, and the best I got was to get a button on every line, except the first line.
And most of the literature discussing this problem is in C#/C++ and I have no idea how to convert the code to python and try it.
Please show me with code, if possible, where I am going wrong, or if I must use a different class.
Regards