Drag & Drop to external application



  • Does Qt provide a cross platform way of getting information of what is under the drag and drop mouse cursor? I'm particularly interested in process name, or window title.

    I've seen programs that use this functionality in Windows (e.g. Power Explorer, where you can get process information on window hover), and in X11, xKill comes to mind.

    In any case, the program about to receive the Drag&Drop seems to communicate with the OS on whether it will accept the drop, based on the Mime Type content. This is apparent from the mouse cursor changing.

    I've not found any documentation on how to access to this information through the Qt Library, and I'm thinking that it simply isn't implemented, even though a crossplatform intersection of functionality seems to exist (though I'm not familiar with Mac OS).

    I've asked this question as well on Stack Overflow, a week ago, but got no good answers. I'm sorry if this is taboo.



  • Hi,

    Qt does not provide such information. This is strongly OS dependant how to get it. On windows you could use a mouse hook and get the window handle of the mouse position and via the window handle, you can find the corresponding process.

    D&D does not give you that information, for D&D this is all done by the OS.



  • Thanks for the answer Gerolf. It's a pity, as it feels like Qt aalmost provides exactly what I need in the actionChanged signal. It knows what the drop action will be, just now which process that told the OS that information.



  • Why is this information important? If you drop your stuff, it's dropped. If it is a move action, you have to delete it afterwards, if it is a copy action, nothing has to be done.

    Or is it more a spy like app you want to do?



  • The program in question contains a lot of engineering data. When the clients want to write a report, exporting various data elements is a nice feature. One way of doing this is through drag and drop. Depending on of the destination drop application, inference can be made on how the drop data should be prepared. E.g. if it's into a text editor, format the data as an image, if its into a spreadsheet, provide the data-points and information for creating the plot.



  • You have to set the mime data before you call the drag start, I'm not sure if it is also possible later on. But you can add several mime types into one drop object, so the destination app can decide, which one to use.

    E.g. you can add text, HTML and a picture if you drag a table.



  • [quote author="EXIT_FAILURE" date="1315314241"]Depending on of the destination drop application, inference can be made on how the drop data should be prepared. E.g. if it's into a text editor, format the data as an image, if its into a spreadsheet, provide the data-points and information for creating the plot.[/quote]

    At the time where you know what application the drag is over, it is far too late to decide on the contents of the drag. You have to prepare those once the drag starts and you cannot change that afterwards. The drag object is handed over to Qt and in turn to the operating system.

    As Gerolf already mentioned, you can put arbitrarily many flavors (distinguished by mime types) of data into the drag object. You are not bound to the predefined types, but you can also add self defined types (use something like "application/x-my-fancy-app-type-1") in order to identify your data.

    Of course that's all speaking of using Qt to prepare the drag contents.

    In the X11 xKill tool a drag'n'drop is not involved, from what I remember. It uses other means to gather that information.



  • [quote author="Volker" date="1315338912"]
    At the time where you know what application the drag is over, it is far too late to decide on the contents of the drag. You have to prepare those once the drag starts and you cannot change that afterwards. The drag object is handed over to Qt and in turn to the operating system.[/quote]

    I'm not sure if I understand you correctly, but it's fully possible to change the contents of the QMimeData object whilst drag is occurring. I just verified it by changing the QMimeData member within a local slot linked to the QDrag object's actionChanged signal (randomly changing the content and outputting it for verification). As for "at the time where you know what application the drag is over [...]", is also a bit strange to mention, as haven't figured out a way to get this information, regardless of "timing". If you know of a Qt way, please let me know :)

    So, if Qt had implemented a callback containing information on the process that issued the actionChanged, I would have all the pieces of the puzzle. My money is on that this is fully possible. Regardless, I'll find a reasonable workaround (e.g. asking the user what kind of destination the drop is to occur in). Whenever you hit a wall, the next logical step is not to.

    edit: As for packing the data in various MimeTypes, and figuring out how the various destination programs prioritize the content is a possible way to do this. However, programming behavior based on a black bock testing gives me nightmares, and I'm at the mercy of external updates. I have to admit that I'm making assumptions about how the MimeType system works, and I know fairly little.



  • Typically, applications check the mime type when a drop enter occures. If the mime type does not fit, the drop is rejected. So if you change the mime type later, it might be that it is too late.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.