我是靠谱客的博主 花痴钢笔,这篇文章主要介绍Qt进阶-事件过滤器eventFilter的使用,现在分享给大家,希望可以做个参考。

事件过滤器eventFilter的使用

如果不提升控件,可以在控件的父对象中为控件安装事件过滤器,从而在父对象中处理子控件的事件;

在父对象源文件中:

//为控件安装事件过滤器
ui.pushButton->installEventFilter(this);
ui.pushButton_2->installEventFilter(this);

bool QtTest::eventFilter(QObject *w, QEvent *event)
{
	QMouseEvent *ev = static_cast<QMouseEvent *>(event);	//事件类型转换
	if (ev->type() == QEvent::MouseButtonPress)				//事件类型
	{
		if(ev->button() == Qt::LeftButton)					//鼠标按键
		{
			QString a = w->objectName();
		}
		
		return true;
	}

	QWidget::eventFilter(watched, event);
}

最后

以上就是花痴钢笔最近收集整理的关于Qt进阶-事件过滤器eventFilter的使用的全部内容,更多相关Qt进阶-事件过滤器eventFilter内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(39)

评论列表共有 0 条评论

立即
投稿
返回
顶部