user372743
user372743

Reputation:

Qt Tray Icon Drag and Drop

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

Upvotes: 6

Views: 1411

Answers (2)

user372743
user372743

Reputation:

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.

Upvotes: 6

James Turner
James Turner

Reputation: 2485

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.

Upvotes: 1

Related Questions