Qt 托盘图标拖放

发布于 2024-09-29 09:34:07 字数 33 浏览 0 评论 0原文

有谁知道是否可以使用 Qt 对托盘图标进行拖放操作?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风铃鹿 2024-10-06 09:34:07

我一直在做一些研究,这就是我得出的结论:

QSystemTrayIcon 无法显式处理拖/放事件。不过,有一个基于 Spifftastic 托盘图标定位方法的解决方法。

  1. 您创建一个独特的彩色图标
    并将其放置为简短的图标
    并截取它的屏幕截图。
  2. 既然你知道颜色
    图标的顺序,您可以
    通过屏幕截图进行搜索并
    找到特定的图标
    地点。
  3. 透明小部件已定位
    位于图标上方并用作
    放下目标。

我还没有研究操作的一些细节,但这就是它的要点。总的来说,这是一种很奇怪的方式,但考虑到没有其他方法可以做到这一点,我认为这是可以接受的。

Fluffy App(用 C# 编写)使用 Spifftastic 方法来定位托盘图标。我假设有关透明窗口的部分是他们如何实现这一点的,但我还没有反编译和检查他们的系统。

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.

同展鸳鸯锦 2024-10-06 09:34:07

由于 QSystemTrayIcon 是 QObject,而不是 QWidget,我的猜测是这是不可能的。系统托盘图标并不真正属于 Qt——它被传递到“桌面”,即 Gnome/KDE/Windows/Mac 的任何部分正在绘制相关区域。至少在 Mac 上,您将把鼠标放在菜单栏上,这将是一个非常奇怪的 UI。对于 Gnome 和 KDE,它是 FreeDesktop.org 标准,但我再次认为您的进程实际上并不进行绘图,因此 Qt 无法向您获取诸如拖放之类的事件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文