开发者

Setting an Item Delegate for rows in a QTreeView when the tree is dynamic

I am using a QTreeView to display a hierarchy of items. Something like this

Child 1
Child 2
Child 3
   Child a
   Child b
   Child c
Child 4
   Child d

The trick is this: The children of Child 3, and Child 4 is a dynamic list. So there can be any number of children under either. I also want to be able to rename each of the nodes, but there are different rules of what is a correct name for the children of Child 3, and Child 4.

I started setting setItemDelegateForRow, but of course that doesn't work, as the children shift up and down in the tree as others are added/removed.

I was hoping there was 开发者_StackOverflow社区a way to attribute an ItemDelegate to a QStandardItem, but it doesn't seem possible.

Any suggestions?


After a lot of investigation and thinking, we found a solution that's not horrible.

We add a check when the selection changes in the tree, and depending on the selection we call setItemDelegate() and pass the desired Delegate for the selected node in the tree.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜