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. How to allow only QAbstractView::AboveItem and BelowItem dragevents in a QTreeWidgetclass and get the source position and destination position
Forum Updated to NodeBB v4.3 + New Features

How to allow only QAbstractView::AboveItem and BelowItem dragevents in a QTreeWidgetclass and get the source position and destination position

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 371 Views
  • 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.
  • S Offline
    S Offline
    Stoke
    wrote on last edited by
    #1

    I'm currently using a custom qt widget class to accomplish this so far. I've been able to use the following code in order to restrict above and below events only, (reorder) and avoid moving items to top level.

    void CustomTreeWidget::dropEvent(QDropEvent *event) {
    
        QModelIndex index = indexAt(event->pos());
        QTreeWidgetItem* item = itemAt(event->pos());
        DropIndicatorPosition position = dropIndicatorPosition();
        if( !index.isValid() )
            return;
        if( position != QAbstractItemView::AboveItem && position != QAbstractItemView::BelowItem ){
            return;
        }
        QTreeWidget::dropEvent(event);
    }
    

    But I'm not sure how to extract both source and destination position. It isn't even very clear what event-pos() refers to in every context. event->source() gives a QObject, but that isn't comparable to QTreeWidgetItems, and I'm not sure how to actually extract the widgetitem or position from the source.

    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