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. Retrieve parent through a Drag & Drop from a QtreeWidget
Forum Updated to NodeBB v4.3 + New Features

Retrieve parent through a Drag & Drop from a QtreeWidget

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 5 Posters 1.1k Views 3 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.
  • C Offline
    C Offline
    coilo
    wrote on last edited by
    #4

    As suggested i am trying to override the QDropEvent function.

    So i wrote in my .h file this :

       void dropEvent(QDropEvent *event) override;
    
    

    and i saw in the documentation that data are stored in a QMime so i have wrote this code to check if i can have the Parent information

    void MainWindow::dropEvent(QDropEvent *event)
    {
        const QMimeData *mimeData = event->mimeData();
        qDebug()<<mimeData->text();
    
    }
    

    But there is nothing displayed. I'm stuck :(, do you have any other ideas?
    Thanks

    SGaistS 1 Reply Last reply
    0
    • M Offline
      M Offline
      mchinand
      wrote on last edited by
      #5

      Did you set the mime data in your QDrag object like in the Drag and Drop example that mrjj linked to above?

      C 1 Reply Last reply
      0
      • M mchinand

        Did you set the mime data in your QDrag object like in the Drag and Drop example that mrjj linked to above?

        C Offline
        C Offline
        coilo
        wrote on last edited by
        #6

        @mchinand Hmmm what do you mean ?
        I have set the mime data like this in my function :

        void MainWindow::dropEvent(QDropEvent *event)
        {
            const QMimeData *mimeData = new QMimeData;
            mimeData = event->mimeData();
        
            qDebug()<<mimeData->text();
         
        }
        
        eyllanescE 1 Reply Last reply
        0
        • C coilo

          @mchinand Hmmm what do you mean ?
          I have set the mime data like this in my function :

          void MainWindow::dropEvent(QDropEvent *event)
          {
              const QMimeData *mimeData = new QMimeData;
              mimeData = event->mimeData();
          
              qDebug()<<mimeData->text();
           
          }
          
          eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by
          #7

          @coilo What is your object wanting to get the parent of the dragged QTreeWidget? Maybe there is another solution. I point this out since by default the dnd between QAbstractItemView (like the QTreeWidget) only sends data encoded in a special format and in that data there is no relationship or information to obtain the parent

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          C 1 Reply Last reply
          0
          • C coilo

            As suggested i am trying to override the QDropEvent function.

            So i wrote in my .h file this :

               void dropEvent(QDropEvent *event) override;
            
            

            and i saw in the documentation that data are stored in a QMime so i have wrote this code to check if i can have the Parent information

            void MainWindow::dropEvent(QDropEvent *event)
            {
                const QMimeData *mimeData = event->mimeData();
                qDebug()<<mimeData->text();
            
            }
            

            But there is nothing displayed. I'm stuck :(, do you have any other ideas?
            Thanks

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #8

            Hi,

            @coilo said in Retrieve parent through a Drag & Drop from a QtreeWidget:

            As suggested i am trying to override the QDropEvent function.

            So i wrote in my .h file this :

               void dropEvent(QDropEvent *event) override;
            
            

            and i saw in the documentation that data are stored in a QMime so i have wrote this code to check if i can have the Parent information

            void MainWindow::dropEvent(QDropEvent *event)
            {
                const QMimeData *mimeData = event->mimeData();
                qDebug()<<mimeData->text();
            
            }
            

            But there is nothing displayed. I'm stuck :(, do you have any other ideas?
            Thanks

            Unless MainWindow is your QTreeWidget it won't get called.

            You need to subclass QTreeWidget if you want to alter its DND behavior.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            C 1 Reply Last reply
            0
            • eyllanescE eyllanesc

              @coilo What is your object wanting to get the parent of the dragged QTreeWidget? Maybe there is another solution. I point this out since by default the dnd between QAbstractItemView (like the QTreeWidget) only sends data encoded in a special format and in that data there is no relationship or information to obtain the parent

              C Offline
              C Offline
              coilo
              wrote on last edited by
              #9

              @eyllanesc Hmmm i see, so there is no way to retrieve the parent's information once the item has been dropped ?

              1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                @coilo said in Retrieve parent through a Drag & Drop from a QtreeWidget:

                As suggested i am trying to override the QDropEvent function.

                So i wrote in my .h file this :

                   void dropEvent(QDropEvent *event) override;
                
                

                and i saw in the documentation that data are stored in a QMime so i have wrote this code to check if i can have the Parent information

                void MainWindow::dropEvent(QDropEvent *event)
                {
                    const QMimeData *mimeData = event->mimeData();
                    qDebug()<<mimeData->text();
                
                }
                

                But there is nothing displayed. I'm stuck :(, do you have any other ideas?
                Thanks

                Unless MainWindow is your QTreeWidget it won't get called.

                You need to subclass QTreeWidget if you want to alter its DND behavior.

                C Offline
                C Offline
                coilo
                wrote on last edited by
                #10

                @SGaist said in Retrieve parent through a Drag & Drop from a QtreeWidget:

                Unless MainWindow is your QTreeWidget it won't get called.

                Hmmm yes my MainWindow is not my QTreeWidget.
                What do you mean by subclassing my QTreeWidget ? What should i change ?

                mrjjM 1 Reply Last reply
                0
                • C coilo

                  @SGaist said in Retrieve parent through a Drag & Drop from a QtreeWidget:

                  Unless MainWindow is your QTreeWidget it won't get called.

                  Hmmm yes my MainWindow is not my QTreeWidget.
                  What do you mean by subclassing my QTreeWidget ? What should i change ?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  @coilo

                  Hi
                  Subclassing means make a new class based on the mentioned class

                  class MyTreeWidget : public QTreeWidget {
                  
                  public:
                      explicit MyTreeWidget(QWidget* parent = nullptr) : QTreeWidget(parent) {}
                  
                  };
                  
                  

                  so you want to add the dropXXX functions to that.

                  and then use MyTreeWidget instead of the plain QTreeWidget

                  C 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @coilo

                    Hi
                    Subclassing means make a new class based on the mentioned class

                    class MyTreeWidget : public QTreeWidget {
                    
                    public:
                        explicit MyTreeWidget(QWidget* parent = nullptr) : QTreeWidget(parent) {}
                    
                    };
                    
                    

                    so you want to add the dropXXX functions to that.

                    and then use MyTreeWidget instead of the plain QTreeWidget

                    C Offline
                    C Offline
                    coilo
                    wrote on last edited by
                    #12

                    @mrjj ah okay thank you I understand a bit better.

                    Hmmmm and what about the dropEvent function what should i change to retrieve the parent information ?

                    mrjjM 1 Reply Last reply
                    0
                    • C coilo

                      @mrjj ah okay thank you I understand a bit better.

                      Hmmmm and what about the dropEvent function what should i change to retrieve the parent information ?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      Hi
                      Super. we need to create our own class (subclass) to change the default drop handlers as they are virtual function and
                      the is the c++ way to implement/change behavior.

                      Hmmmm and what about the dropEvent function what should i change to retrieve the parent information ?

                      Well Im not 100% sure that the default MimeData contains both row and col.

                      The standard mimeformat used can be read like this

                      https://stackoverflow.com/questions/1723989/how-to-decode-application-x-qabstractitemmodeldatalist-in-qt-for-drag-and-drop

                      so it might be enough.

                      If not, you need to handle the DragStart function also to include the information you need.

                      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