views:

39

answers:

3

Does anyone know if it is possible to use drag and drop with a tray icon using Qt?

A: 

I don't really know much about Qt but this might lead you in the right direction: http://web.njit.edu/all_topics/Prog_Lang_Docs/html/qt/simple_dd-example.html

Sorry if that is a dead end or terrible help.

Robert Massaioli
A: 

Since QSystemTrayIcon is a QObject, not a QWidget, my guess is this is not possible. The system tray icon isn't really owned by Qt - it's passed on to the 'desktop', i.e whatever part of the Gnome/KDE/Windows/Mac is drawing the relevant area. At least on Mac, you'd be dropping on the menu-bar, which would be a very strange UI. For Gnome and KDE it's a FreeDesktop.org standard, but again I don't think its your process which actually does the drawing, and hence there's no way for Qt to get events such as drag and drop to you.

James Turner
+2  A: 

I've been doing some research and here is what I have come up with:

A QSystemTrayIcon cannot explicitly handle a drag/drop event. However there is a workaround based on the Spifftastic tray icon location method.

  1. You create a uniquely colored icon and place it as the icon for a brief moment and take a screenshot of it.
  2. Given that you know the color sequence for the icon, you can search through the screenshot and locate the particular icon's location.
  3. A transparent widget is positioned over the icon and is used as the drop target.

I have yet to work at a few of the finer details of the operation but that is the gist of it. All things considered it is a hacky way of things but given that there are no other ways to do this I think it is acceptable.

Fluffy App (written in C#) uses the Spifftastic method to locate the tray icon. I'm assuming the part about the transparent window is how they accomplish that but I have yet to decompile and examine their system.

Glenn Nelson