PDA

View Full Version : QTreeView Drag&Drop Indicator above&below only shown when items have children



flautzr
30th August 2019, 09:37
Hi,

I have a QTreeView where I want to enable the user to sort the items by drag&drop. Dropping an item onto another (QAbstractItemView::DropIndicatorPosition::OnItem) should add the item as a child, and dropping when DropIndicatorPosition::AboveItem or DropIndicatorPosition::BelowItem is shown should insert the item before/after the target on the same level.

The problem is that the AboveItem/BelowItem Indicators are only shown when the items have children, making it possible to insert the item into another but leaving it impossible to change the order when the neighboritems dont have children.

I have tried setting DragDropMode to InternalMove (since there is no Drag&Drop between TreeViews) but that makes it buggy (DragMoveEvent is overwritten and checks every item individually if a drop is possible) and does'nt help. Is it possible to activate above/below indicators permanently for all items?

edit: after some fiddling with this i have seen that my assumption that the indicators dont get displayed for items without children is not entirely right. they got shown for childless items, but only when they were previously unchecked (all the items in the tree are set to checkable) and even then they only got shown for a few of them. Sometimes the view doesnt update when hovering over them and DragMoveEvent is called, but only on childless items, so something is not working right here. I would be very thankful if anyone has a clue as how to fix this behaviour.