Get position of widget under cursor during drag and drop in a QTreeWidget
-
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.
-
I change the code to read:
QPoint position = timingTree->mapToGlobal( moveEvent->position( ).toPoint( ) ); QToolTip::showText( position, error.what( ), ui->timingTree );and this works.
-
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.
@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
-
I change the code to read:
QPoint position = timingTree->mapToGlobal( moveEvent->position( ).toPoint( ) ); QToolTip::showText( position, error.what( ), ui->timingTree );and this works.
-
G gabello306 has marked this topic as solved