Qt禁用鼠标事件响应

本文阅读 1 分钟
首页 应用开发 正文

引言

QT中很多控件都有鼠标点击的事件响应,比如QPushButton,QRadioButton。有时候我们想要实现的是:当鼠标点击控件时,不会产生响应事件。其中的一种方法是使用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);
本文来自投稿,不代表本站立场,如若转载,请注明出处:
常见的数据结构及算法
« 上一篇 03-19
Qt使用OpenSSL库
下一篇 » 03-26