Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTreeView drag & drop issue



  • Hi

    I use QTreeView+QStandardItemModel to create multi column tree widget, with Qt 4.7 libs.

    The [Company] column has items that behave as parent in order to create a group of companies under a particular city.

    @
    Columns:
    Company |Website |Phone

    +City X
    --Company A|exampleA.com|phone A
    --Company B|exampleB.com|phone B
    --Company C|exampleC.com|phone C
    +City Y
    --Company D|exampleD.com|phone D
    --Company E|exampleE.com|phone E
    --Company F|exampleF.com|phone F
    @

    The default drop action is MoveAction. I want to drag row from one group to another, say to move Company F into City X group.

    When I drag [Company F] item it can as well be dropped in [Phone B] item in group City X. This action moves the row to another group but it is shifted on the right, [Company F] item starts in the [Phone] column.

    To avoid this I set setDragEnabled(false) and setDropEnabled(false) to all items except those in the first column [Company];

    Again it is allowed to drop/move [Company] item into [Phone] column of another row.

    Any suggestions?

    [EDIT: code formatting for ASCII art, Volker]



  • Any opinions whether this is a bug?



  • No, it's not a bug. Per default you can drag any item and drop it anywhere. My experience taught me to handle the drag and drop stuff manually, and not rely on the built-in methods, if you have constraints on where a drop can occur.



  • [quote author="Volker" date="1328914895"]No, it's not a bug. Per default you can drag any item and drop it anywhere. [/quote]

    What's the use of QStandardItem::setDropEnabled then? When this is set to false the item still accepts drops.



  • [quote author="Marcus Frenkel" date="1328951033"]
    What's the use of QStandardItem::setDropEnabled then? When this is set to false the item still accepts drops.[/quote]

    Sorry, I don't know that. We never used the standard item models in our projects together with DnD.


Log in to reply