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. Get position of widget under cursor during drag and drop in a QTreeWidget
Qt 6.11 is out! See what's new in the release blog

Get position of widget under cursor during drag and drop in a QTreeWidget

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 129 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.
  • G Offline
    G Offline
    gabello306
    wrote last edited by
    #1

    I am performing a drag and drop from a QListWidget to a QTreeWidget. Using the following code I can get a position during the mouse movement but the QToolTip::showText seems to be displayed in Global coordinates instead of coordinates inside the QTreeWidget.

            // Drag move event
            QDragMoveEvent *moveEvent = static_cast<QDragMoveEvent *>( event );
                
            QTreeWidgetItem *hoveredItem =
                    timingTree->itemAt( moveEvent->position( ).toPoint( ) );
    
            QPoint pt = moveEvent->position( ).toPoint( );
    
            QPoint globalPos = widget->mapFromGlobal( QPoint( 0, 0 ) );
    
            QToolTip::showText( pt, error.what( ), ui->timingTree );
    
    

    ui->timingTree is of type QTreeWidget and error.what() is just a text string. What I need to know is how to put the showText box in the QTreeWidget instead of global coordinates.

    Christian EhrlicherC 1 Reply Last reply
    0
    • G Offline
      G Offline
      gabello306
      wrote last edited by
      #3

      I change the code to read:

                  QPoint position =
                      timingTree->mapToGlobal( moveEvent->position( ).toPoint( ) );
      
                  QToolTip::showText( position, error.what( ), ui->timingTree );
      

      and this works.

      1 Reply Last reply
      1
      • G gabello306

        I am performing a drag and drop from a QListWidget to a QTreeWidget. Using the following code I can get a position during the mouse movement but the QToolTip::showText seems to be displayed in Global coordinates instead of coordinates inside the QTreeWidget.

                // Drag move event
                QDragMoveEvent *moveEvent = static_cast<QDragMoveEvent *>( event );
                    
                QTreeWidgetItem *hoveredItem =
                        timingTree->itemAt( moveEvent->position( ).toPoint( ) );
        
                QPoint pt = moveEvent->position( ).toPoint( );
        
                QPoint globalPos = widget->mapFromGlobal( QPoint( 0, 0 ) );
        
                QToolTip::showText( pt, error.what( ), ui->timingTree );
        
        

        ui->timingTree is of type QTreeWidget and error.what() is just a text string. What I need to know is how to put the showText box in the QTreeWidget instead of global coordinates.

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote last edited by
        #2

        @gabello306 said in Get position of widget under cursor during drag and drop in a QTreeWidget:

        What I need to know is how to put the showText box in the QTreeWidget instead of global coordinates.

        You have to convert the local coordinates to the global ones: https://doc.qt.io/qt-6/qwidget.html#mapToGlobal

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        3
        • G Offline
          G Offline
          gabello306
          wrote last edited by
          #3

          I change the code to read:

                      QPoint position =
                          timingTree->mapToGlobal( moveEvent->position( ).toPoint( ) );
          
                      QToolTip::showText( position, error.what( ), ui->timingTree );
          

          and this works.

          1 Reply Last reply
          1
          • G gabello306 has marked this topic as solved

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved