mouseevent - pyqt QGraphicsView mouse events trouble -


i'm writing mdi application qgraphicsview on each tab. add items, move them , there group. there number of problems, such as:

  • a one-time allocation of objects. can not rubber band select objects , holding shift add selection other rubber band selection. can done example if before new allocation remember old objects , add after separation previously. done through mouse events, , not work @ all

  • necessary when click on object action, done through mouse events ...

  • i need mouse wheel zoom, , rests on mouse events

possible of these actions have no ready-made solutions zalezaniya in mouse events, lessons find - mouse events save me

how make qgraphicsview catch mouse events?

import os import sys import sip import maya.openmayaui mui pyqt4.qtcore import * pyqt4.qtgui import *  #---------------------------------------------------------------------- def getmayawindow():     ptr = mui.mqtutil.mainwindow()     return sip.wrapinstance(long(ptr), qobject)  #---------------------------------------------------------------------- #---------------------------------------------------------------------- class mainform(qmainwindow):     def __init__(self):         super(mainform, self).__init__(getmayawindow())         self.setgeometry(50,50,600,600)          widget = qwidget()         self.setcentralwidget(widget)         layout = qgridlayout()         widget.setlayout(layout)          mdiarea = qmdiarea()         layout.addwidget(mdiarea)          newitem1 = vrayrectwidget(mdiarea, 'aaaa')         newitem2 = vrayrectwidget(mdiarea, 'bbbb')          newitem1.setmousetracking(true)         newitem2.setmousetracking(true)  #---------------------------------------------------------------------- #---------------------------------------------------------------------- class vrayrectwidget(qmdisubwindow):     def __init__(self, parent, name):         super(vrayrectwidget, self).__init__(parent)         self.setattribute(qt.wa_deleteonclose)         self.setwindowtitle(name)          self.view = myview()         self.view.setmousetracking(true)         self.setwidget(self.view)   #---------------------------------------------------------------------- #---------------------------------------------------------------------- class myview(qgraphicsview):     def __init__(self):         qgraphicsview.__init__(self)          self.setgeometry(qrect(100, 100, 600, 400))         self.setdragmode(qgraphicsview.rubberbanddrag)         self.setrubberbandselectionmode(qt.intersectsitemshape)         self.setmousetracking(true)          self.setrenderhints(qpainter.antialiasing | qpainter.smoothpixmaptransform)          self.scene = qgraphicsscene(self)         self.scene.setscenerect(qrectf())         self.setscene(self.scene)         self.setinteractive(true)          in range(5):             item = qgraphicsellipseitem(i*75, 10, 60, 40)              item.setflag(qgraphicsitem.itemismovable, true)             item.setflag(qgraphicsitem.itemisselectable, true)             self.scene.additem(item)      def mousepressevent(self, event):         print('mousepressevent')  #---------------------------------------------------------------------- #---------------------------------------------------------------------- # window def cachewnd():     wnd = mainform()     wnd.show()  cachewnd() 

you need eventfilter in myview:

def eventfilter(self,obj,event):     if obj == self , event.type() == qtcore.qevent.mousebuttonpress:      # see http://doc.qt.io/qt-5/qevent.html     # alternatively use qtcore.qevent.graphicsscenemousepress         print('mousepressevent')         return true     return qtwidgets.qgraphicsview.eventfilter(self,obj,event) 

and install him @ end of constructor of myview:

self.installeventfilter(self) 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -