Qt如何检查按下了哪个鼠标按钮 [英] Qt how to check which mouse button is pressed

查看:90
本文介绍了Qt如何检查按下了哪个鼠标按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PySide 中尝试确定事件函数中按下了哪个鼠标按钮时遇到问题.我特别需要它来忽略鼠标移动事件,因为它在左右鼠标按钮上都在工作.

I have problems in PySide while trying to determine which mouse button is pressed in event function. I need it in particular for ignoring mouse move event, because it's doing job on both mouse buttons, left and right.

如果按下场景上的右键,我想忽略鼠标移动事件.有什么帮助吗?

I want to ignore mouse move event if the right button on scene is pressed. Any help?

推荐答案

所有的鼠标事件都有两个方法(buttonbuttons)来确定哪个按钮被按下.但仅对于 move 事件,文档说:

All of mouse events have two methods (button and buttons) to determine which of buttons are pressed. But for only move event the documentation says:

请注意,鼠标移动事件的返回值始终为 Qt::NoButton.

Note that the returned value is always Qt::NoButton for mouse move events.

对于 mouseMoveEvent 你应该使用 buttons 方法.

for mouseMoveEvent you should use buttons method.

void mouseMoveEvent(QMouseEvent *e)
{
    if(e->buttons() == Qt::RightButton)
        qDebug() << "Only right button";
}

为了忽略移动事件,你当然需要在 eventFilter 中完成这项工作.

In order to ignore move events you need to do this work in eventFilter of course.

这篇关于Qt如何检查按下了哪个鼠标按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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