Qt - 具有键盘和鼠标事件透明度的顶级小部件? [英] Qt - top level widget with keyboard and mouse event transparency?

查看:35
本文介绍了Qt - 具有键盘和鼠标事件透明度的顶级小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望应用程序的主窗口忽略鼠标和键盘事件,将它们传递给窗口管理器 Z-order 中它下面的应用程序.

I want an app's main window to ignore mouse and keyboard events, passing them to applications underneath it in the window manager Z-order.

我知道如何让小部件忽略键盘或鼠标事件,但是主窗口呢?

I see how to make child widgets ignore keyboard or mouse events, but how about the main window?

我正在尝试制作一个桌面小部件,它始终位于背景上方,并且对键盘和鼠标事件完全不可见.(通过)

I'm trying to make a desktop widget that always sits just over the background and is totally invisible to keyboard and mouse events. (Pass through)

Qt::X11BypassWindowManagerHint 让我通过键盘(虽然遗憾的是 X11 特定,但现在还好),那么鼠标事件呢?

Qt::X11BypassWindowManagerHint gets me keyboard pass through (although sadly X11 specific, but fine for now), so how about mouse events?

是否有一种与操作系统无关的方式来对键盘事件透明?

Is there a OS-agnostic way to be transparent to keyboard events?

这里的关键词是透明度.

The key word here is transparency.

我不想 EAT 鼠标和键盘事件,我想让窗口管理器知道我根本不需要它们.这些事件应该指向 zorder 中我下面的任何应用程序.

I don't want to EAT mouse and keyboard events, I want the window manager to know I don't want them at all. Those events should be directed to whatever application is under me in the zorder.

例如,我希望能够点击我的小部件覆盖的桌面图标并与它们交互,就好像小部件不存在一样.

For example, I want to be able to click on desktop icons that are covered by my widget and interact with them as if the widget was not there.

推荐答案

我找到了以下解决方案(在 Linux 上测试,根据@TheSHEEEP 也适用于 Windows):

I found the following solution (tested on Linux, also works on Windows according to @TheSHEEEP):

setWindowFlags(windowFlags() | Qt::WindowTransparentForInput);

它已添加到最近的 qt 版本中(我没有找到何时)见 http://doc.qt.io/qt-5/qt.html

It has been added in more recent qt release (i did not find when) see http://doc.qt.io/qt-5/qt.html

这篇关于Qt - 具有键盘和鼠标事件透明度的顶级小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆