from PyQt4.QtCore import *
from PyQt4.QtGui import *
def __init__(self,x,y,w,h,parent):
self.setPos(x,y)
self.
setPen(QPen(Qt.
NoPen)) def wheelEvent(self,event):
print "Item got a wheel"
def __init__(self):
def wheelEvent(self,event):
print "scene got a wheel"
scene = MyScene()
layout.addWidget(view)
dialog.setLayout(layout);
m1 = MyItem(0,0,100,100,None)
scene.addItem(m1)
view.setScene(scene)
dialog.show()
app.exec_()
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class MyItem(QGraphicsRectItem):
def __init__(self,x,y,w,h,parent):
QGraphicsRectItem.__init__(self,w/2.0,h/2.0,w,h,parent)
self.setPos(x,y)
self.setPen(QPen(Qt.NoPen))
self.setBrush(QBrush(QColor(Qt.black)))
def wheelEvent(self,event):
print "Item got a wheel"
class MyScene(QGraphicsScene):
def __init__(self):
QGraphicsScene.__init__(self)
def wheelEvent(self,event):
print "scene got a wheel"
app = QApplication([])
dialog = QDialog()
view = QGraphicsView()
scene = MyScene()
layout = QVBoxLayout()
layout.addWidget(view)
dialog.setLayout(layout);
m1 = MyItem(0,0,100,100,None)
scene.addItem(m1)
view.setScene(scene)
dialog.show()
app.exec_()
To copy to clipboard, switch view to plain text mode
Bookmarks