Qt Tray Icon Drag and Drop

余生颓废 提交于 2021-02-07 07:16:47

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4011348/qt-tray-icon-drag-and-drop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!