PyQt.如何在鼠标右键单击时阻止清除选择? [英] PyQt. How to block clear selection on mouse right click?

查看:46
本文介绍了PyQt.如何在鼠标右键单击时阻止清除选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 QGraphicsScene 和许多可选项目.但是当我单击鼠标右键时 - 取消选择所有对象.我想显示菜单并编辑选定的对象,但在鼠标右键单击时可以随时自动取消选择...

I have a QGraphicsScene and many selectable items. But when I click the right mouse button - deselects all objects. I want show menu and edit selected objects but have automatic deselect any time when right click at mouse...

也许问题在于我包含了一个橡胶选择.选择的对象到底是怎么拉框的时候鼠标左右键的,所以单次按右键就重置了...

Perhaps the problem is that I have included an rubber selection. selection of objects in the end is how the right and the left mouse button when I pull the frame and therefore is reset at single time you press the right button...

如何在单击鼠标右键时突出显示对象?或者可能需要禁用右键的橡胶选择?

How to leave objects highlighted when you click on the right mouse button? Or it may be necessary to disable the rubber selection of the right button?

推荐答案

Daniele Pantaleone 的回答给了我一个思路,我修改了mousePressEvent() 的函数,立马得到了想要的效果我

Daniele Pantaleone answer gave me an idea and I have modified the function of mousePressEvent() and immediately got the desired effect me

def mousePressEvent(self, event):
    if event.button() == Qt.MidButton:
        self.__prevMousePos = event.pos()
    elif event.button() == Qt.RightButton: # <--- add this 
        print('right')
    else:
        super(MyView, self).mousePressEvent(event)

这篇关于PyQt.如何在鼠标右键单击时阻止清除选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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