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. QTreeWidget Drag and Drop InternalMove problems
Qt 6.11 is out! See what's new in the release blog

QTreeWidget Drag and Drop InternalMove problems

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.8k 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.
  • D Offline
    D Offline
    dysplaced
    wrote on last edited by
    #1

    I am using a QTreeWidget with Drag and Drop operations and dragDropMode set to InternalMove.
    For the most part, this works as expected, with one exception:

    1. I want to allow dropping only for certain items, depending on the dragged item. I have overridden dragMoveEvent to only accept events where my constraints hold. This works, except for one constraint: I do not want it to be possible for an item to be dragged to root level. I do not know how to achieve this.
      For my other constraints, I use itemAt(event.pos()) to get the target item. However, when I drag to a position just above a root level item (in the GUI, the root item is no longer marked - instead there is a horizontal line above it), this also gives me the root item, so I can't use it to decide whether I will be dragging to root level or into a root item.

    This is supposed to be allowed and works fine:
    !http://s16.postimage.org/ckt4nx491/dragright.png(Drop should be allowed)!

    This is supposed to be forbidden, but I don't see a way to distinguish it from the first case:
    !http://s16.postimage.org/v5hcuzpol/dragwrong.png(Drop should not be allowed)!

    1 Reply Last reply
    0
    • N Offline
      N Offline
      neuviemep
      wrote on last edited by
      #2

      You don't need to override dragMoveEvent to do this. When creating the items, use setFlags() to set Qt::ItemIsDragEnabled for items which can be dragged and Qt::ItemIsDropEnabled for items which can be targets of a drag.

      To prevent the widget from accepting drags to the root level, access the root item with invisibleRootItem() and clear the "drop enabled" flag on it.

      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