Drop From QML to QTreeView



  • I have a QTreeView with a QStandarditemModel as model and actually I enabled the Drag&Drop on the tree's items.

    Now I want to drop a element from a QML scene (I created the mimedata for the QML element) into the tree, but I'm unable to do it.

    I overrided the flags method

    Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
    {
        if (index.isValid()) {
            return QStandardItemModel::flags(index);
        }
    
        return QStandardItemModel::flags(index) | Qt::ItemIsDropEnabled;
    }
    

    Also with simple text, if I drop it into the tree, I don't see the drop icon.



  • Hi
    QTreeView also requires you to enable drops in the view. Did you do this ?

    view->setAcceptDrops(true); 
    

    Also I noticed that you only return the ItemIsDropEnabled flag if your index is invalid, you may have missed a ! in your test (unless you only want to accept drops on the root item). Put a breakpoint at the start of the TreeModel::flags function and see if it breaks to make sure that the view actually asks the model if a drop is available.


Log in to reply
 

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