忽略Qt中的鼠标和键盘事件 [英] Ignore mouse and keyboard events in Qt

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

问题描述

在Qt中,我如何才能忽略所有鼠标和键盘事件,然后又停止忽略它们?即:单击一个按钮,忽略子级中的所有事件;再次单击,不要忽略.明白了吗? 我有以下几行,但也许我做错了事:

In Qt, how can I ignore all mouse and keyboard events and later stop ignoring them? That is: click a button, ignore all events in children; click again, not ignore. Is that clear? I have the following lines, but maybe I'm doing something wrong:

setAttribute(Qt::WA_TransparentForMouseEvents);

setFocusPolicy(Qt::NoFocus);

推荐答案

不要使用setFocusPolicy(Qt :: NoFocus);它将事件传播到父级.仅使用setAttribute(Qt :: WA_TransparentForMouseEvents);

Dont use setFocusPolicy(Qt::NoFocus); and it will propagate events to the parent. Use only setAttribute(Qt::WA_TransparentForMouseEvents);

这篇关于忽略Qt中的鼠标和键盘事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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