Stopping dragged item dropping on top of other item



  • Hi All,
    I've set up a tree view which lists my items. I can drag and drop items in the view, however if I drop an item on top of an other it becomes a "branch" of that item. Basically if I have the below list abd move item 2 ontop of 3 it becomes part of it so
    original
    ---item 1
    ---item 2
    ---item 3
    ---item 4

    move 2 and accidentally drop on item 3 rather than in gap ( difficult to show because of formatting )
    ---item 1
    ---item 3
    ..................|--- item 2
    ---item 4

    How can I set it up do if I drop on an other item it moves above or below it? I can see this enum "QAbstractItemView::BelowItem" but if this is the solution I don't know how to use it? Thanks! My set up is below
    [code]

    ui->treeView_2->setModel(  ListItem.get_tree_model( ) );
    ui->treeView_2->setDropIndicatorShown( true );
    ui->treeView_2->setDragEnabled( true );
    ui->treeView_2->setSelectionBehavior( QAbstractItemView::SelectRows );
    ui->treeView_2->setDragDropMode(QAbstractItemView::InternalMove);
    

    [/code]


  • Lifetime Qt Champion

    Hi,

    You have to re-implement the drop handling of QTreeView if you want to avoid that.

    If you want to have only a one column view, then why not use QListView ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.