Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Drop From QML to QTreeView
Qt 6.11 is out! See what's new in the release blog

Drop From QML to QTreeView

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 760 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • giupignaG Offline
    giupignaG Offline
    giupigna
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Smatcher
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved