Important: Please read the Qt Code of Conduct -

Intra and inter application drag and drop; how know if a drag originated in self/this?

  • Using Qt, if you start a drag ( create a QDrag and call exec_() on it), is there any way to distinguish DragMoveEvents() from drags that started in this app instance, from drags that started in another app instance?

    The context is, my app already implements drag of document elements without using the Qt D&D mechanisms. (Its for repositioning, I just call QGraphicItem.setPos().) Lets refer to that as a 'local drag.' But I want to support drag to other applications ('external drag'.) I plan to create a QDrag only when the mouse (with button down) leaves my main window. But it seems like there might be a grab in effect, and this app instance might receive DragMoveEvents() for a local drag that started in this (especially if the user moves the mouse back into any window of this app.)

    I suppose I could just set a flag.

    Or possibly I should forego my implementation of a 'local drag', except that entails extra conversions back and forth to QMimeData. (Qt's D&D, as opposed to my own implementation, isn't more useful to the user, the user can still see that the document element is being dragged because I ghost it.)

    I don't think that QDrag.source() widget pointer will distinguish local from external drag. It seems to me that drops from external apps could not refer to widgets in the drag source app. I.E. a QDrag.source() always refers to a widget in the app that is receiving a drag, even an external drag that started in another app. I.E. 'source' cannot mean 'source app's widget', only: 'the widget in this app where the drag first entered this app's windows.'

    Or am I missing the fact that I won't receive QDragMoveEvents() in the same widget that started a drag?

Log in to reply