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. Restrict what can be dragged from a QTreeView
Forum Updated to NodeBB v4.3 + New Features

Restrict what can be dragged from a QTreeView

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 377 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.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #1

    I really will keep this one brief! :)

    Code has a QTreeView. It allows dragging of elements out to a QGraphicsView. I didn't write any of the code for this, haven't done drag & drop. There's no MIME stuff, no code I can see in the treeview side, no creation of drag objects, just:

    self.treeView_blklib.setDragEnabled(True)
    self.treeView_blklib.setDragDropOverwriteMode(True)
    self.treeView_blklib.setDragDropMode(QtWidgets.QAbstractItemView.DragOnly)
    

    so I guess that all works internally.

    All I want to know is: I want to restrict so that the tree leaves can still be dragged but the nodes cannot. How simply can that be achieved? Do I have to perhaps introduce a mouse-down handler and do something there?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Overwrite QAbstractItemModel::flags()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      JonBJ 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        Overwrite QAbstractItemModel::flags()

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Christian-Ehrlicher
        I wondered whether there might be a flag for dragable on my way home after I posted! I see https://doc.qt.io/qt-5/qt.html#ItemFlag-enum, Qt::ItemIsDragEnabled 4 It can be dragged.. Perfecto-mundo, thank you :)

        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