QT实现控件不响应鼠标点击事件

QT中很多控件都有鼠标点击的事件响应,比如QPushButton,QRadioButton。有时候我们想要实现的是:当鼠标点击控件时,不会产生响应事件。其中的一种方法是使用Qt::WA_TransparentForMouseEvents。

官方对Qt::WA_TransparentForMouseEvents的说明为

When enabled, this attribute disables the delivery of mouse events to the widget and its children. Mouse events are delivered to other widgets as if the widget and its children were not present in the widget hierarchy; mouse clicks and other events effectively "pass through" them. This attribute is disabled by default.

大概的意思是当使能Qt::WA_TransparentForMouseEvents时,鼠标事件就不会传送到该控件及子控件,而是会传到其他的不包含该控件的widget上,这样的话其实就是实现了鼠标穿透的功能。

实现代码

ui->radioButton->setAttribute(Qt::WA_TransparentForMouseEvents, true);

使radioButton控件不响应鼠标点击事件。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值