Thanks to this thread, I\'m able to add widgets to 2nd or later column of QAbstractItemView
(in my example QTreeView) of top level items of a view
.
Your mistake is on this line:
qindex_widget_child = self._datamodel.index(n, 1, QModelIndex())
self.setIndexWidget(qindex_widget_child, node_widget_child)
It's giving you the index on row 2 column 1 of the model, which is the "2th item", not your child. Your child is on row 1 column 1 of std_item
. In Qt, especially in QStandardItemModel, Children are stored relative to their parent, not relative to the model.
I'm not familiar enough with PyQt to give you the exact code, but you should be able to do something like this:
qindex_widget_child = std_item_child.index(QModelIndex())
self.setIndexWidget(qindex_widget_child, node_widget_child)
or like this:
qindex_widget_child = std_item.child(0, 1).index(QModelIndex())
self.setIndexWidget(qindex_widget_child, node_widget_child)