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 find parent, current item, old parent in dropEvent
Forum Update on Monday, May 27th 2025

QTreeWidget find parent, current item, old parent in dropEvent

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

    I have a QTreeWidget that supports drop & drops. To prevent invalid drop & drops, I need to find out where the item was taken from, where it is going, and what item was taken.

    Currently I do this:
    @
    void dropEvent(QDropEvent *event){
    QTreeWidgetItem * pItem = itemAt( event->pos() );
    QTreeWidgetItem * oldpItem = itemFromIndex( oldModel );//oldModel is set earlier
    QTreeWidgetItem * cItem;
    QString source = event->source()->objectName();
    for(int i=0;i<oldpItem->childCount();i++){
    QTreeWidgetItem * item = oldpItem->child(i);
    if (item->text(0) == source){
    cItem = item;
    break;
    }
    }
    @

    The current item is what I am unable to find. This approach crashes at the moment. Is there a simpler way to get what item is being moved?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Peppy
      wrote on last edited by
      #2

      Thats good question, I am exposed to this issue too. Maybe this old bug is still in play: "QTBUG-676":https://bugreports.qt-project.org/browse/QTBUG-676

      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