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

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

问题描述

我想要一个应用程序的主窗口忽略鼠标和键盘事件,将它们传递到窗口管理器Z顺序中的应用程序。



我看到如何使小孩小部件忽略键盘或鼠标事件,但主窗口如何?



我试图制作一个总是坐在背景上的桌面小部件,完全不受键盘和鼠标事件的影响。 (通过)



Qt :: X11BypassWindowManagerHint 让我键盘通过(虽然可悲的是X11具体,但现在很好),那么怎么样鼠标事件?



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



编辑:



这里的关键词是透明度。



我不想 EAT 鼠标和键盘事件,我希望窗口管理员知道我根本不想要它们。这些事件应该针对我在zorder中的任何应用程序。



例如,我想要能够点击我的小部件所覆盖的桌面图标,

解决方案

在Windows上,您可以设置 WS_EX_TRANSPARENT

包含头部

  #if _WIN32 
#include< windows.h>
#endif

并将以下代码放入构造函数中。

  #if _WIN32 
HWND hwnd =(HWND)winId();
LONG styles = GetWindowLong(hwnd,GWL_EXSTYLE);
SetWindowLong(hwnd,GWL_EXSTYLE,styles | WS_EX_TRANSPARENT);
#endif


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 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?

EDIT:

The key word here is transparency.

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.

解决方案

On Windows you can set WS_EX_TRANSPARENT

To do this in Qt use the following code:

Include the header,

#if _WIN32
    #include <windows.h>
#endif

and put the following code into the constructor.

#if _WIN32
    HWND hwnd = (HWND) winId();
    LONG styles = GetWindowLong(hwnd, GWL_EXSTYLE);
    SetWindowLong(hwnd, GWL_EXSTYLE, styles | WS_EX_TRANSPARENT);
#endif

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

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