Qt - 有选择地允许点击进入较低的应用程序窗口 [英] Qt - selectively allow a click to fall through to a lower application window

查看:85
本文介绍了Qt - 有选择地允许点击进入较低的应用程序窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在 Qt 应用程序中接收鼠标点击并对其进行评估,并在必要时让它落入 Qt 应用程序窗口下方可能发生的任何地方?

Is it possible to receive a mouse click even in a Qt application, evaluate it, and if necessary, let it fall through to whatever might happen to be below the Qt application window?

请注意,Qt::WA_TransparentForMouseEvents 在传递点击之前并不有助于评估点击.

Note that Qt::WA_TransparentForMouseEvents doesn't facilitate evaluating the click before passing it through.

并且由于点击评估包含一些动态逻辑,因此也不适用于设置静态掩码,此外还有视觉冲击.

And since the click evaluation incorporates some dynamic logic, it is not applicable to set a static mask either, on top of this having a visual impact as well.

理想情况下,我想要一种方法来选择性地允许鼠标单击以平台可移植的方式通过应用程序窗口,理想情况下来自 QML 并且不引入小部件模块,或者至少不涉及挖掘私有C++ 内部 API.

Ideally, I would like a way to selectively allow the mouse click to pass through the application window in a platform portable way, ideally from QML and without bringing in the widgets module, or at the very least, without involving digging into private C++ internal APIs.

推荐答案

Qt::WA_TransparentForMouseEvents 用于过滤鼠标事件.这个名字有点用词不当:它允许小部件否则会消耗鼠标事件,而不是消耗它们.例如.您可以使按钮不注意任何鼠标事件.如果您正在编写自定义小部件,则永远不需要此属性,因为由您来检查鼠标事件而不处理它们:它们会自动传递给父小部件.

Qt::WA_TransparentForMouseEvents is used to filter mouse events out. The name is a bit of a misnomer: it allows widgets that would otherwise consume mouse events, not to consume them. E.g. you could make a button not notice any mouse events. If you're writing a custom widget, there's never any need for this attribute, since it's up to you to inspect the mouse events and simply not handle them: they are automatically passed to the parent widget.

但所有这些都无关紧要,因为 WA_ 属性用于小部件,而对 Windows 没有任何作用.你完全想要别的东西:使窗口本身对输入透明.因此,在 QML 中:

But all of this doesn't matter much, since the WA_ attributes are for widgets, and do nothing for windows. You want something else entirely: to make the window itself transparent for input. Thus, in QML:

window.flags = window.flags | Qt.WindowTransparentForInput

这篇关于Qt - 有选择地允许点击进入较低的应用程序窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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