Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    QTreeWidget find parent, current item, old parent in dropEvent

    General and Desktop
    2
    2
    1838
    Loading More Posts
    • 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
      chrismit7 last edited by

      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 Reply Quote 0
      • P
        Peppy last edited by

        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 Reply Quote 0
        • First post
          Last post