I recently updated from 4.7 to 4.7.3 and suddenly the QGraphicsItem class no
longer
seems to have a setOpacity method. The documentation still indicated that
should be
a valid method. In addition I noticed that the ItemUsesExtendedStyleOption
attribute is also missing from the QGraphicsItem class.
Attached is some test code I have featuring has a class called CustomItem which
inherits from QGraphicsItem and attempts to call setOpacity in it's
constructor.
When I run it I get the following errror:
Traceback (most recent call last):
File "./test.py", line 63, in <module>
item=CustomItem(None,None)
File "./test.py", line 13, in __init__
self.setOpacity(.9)
AttributeError: 'CustomItem' object has no attribute 'setOpacity'
Please let me know if I somehow have a bad installation or if there's something
I
can do to fix this.
Thanks,
Buddy Becker#!/usr/bin/env python
import sys
import PyQt4.QtGui as qtgui
import PyQt4.QtCore as qtcore
from Queue import Queue
class CustomItem(qtgui.QGraphicsItem):
def __init__(self,parent=None,scene=None):
qtgui.QGraphicsItem.__init__(self,parent,scene)
self.image=qtgui.QImage(200,200,qtgui.QImage.Format_ARGB32_Premultiplied)
self.image.fill(0xffffffff)
# !! either of these next two lines fail !!
self.setOpacity(.9)
self.setFlag(qtgui.QGraphicsItem.ItemUsesExtendedStyleOption)
self.dirtyrect=qtcore.QRectF()
def drawPoint(self,x,y):
painter=qtgui.QPainter()
painter.begin(self.image)
rect=qtcore.QRect(x,y,3,3)
painter.fillRect(rect,qtgui.QColor(0,0,0))
view.updateScene([qtcore.QRectF(rect)])
def boundingRect(self):
return qtcore.QRectF(self.image.rect())
def paint(self,painter,options,widget=None):
drawrect=options.exposedRect
painter.drawImage(drawrect,self.image,drawrect)
self.dirtyrect=qtcore.QRectF()
class CustomGraphicsView(qtgui.QGraphicsView):
def paintEvent(self,event):
rect=event.rect()
qtgui.QGraphicsView.paintEvent(self,event)
class CustomScene(qtgui.QGraphicsScene):
def __init__(self,rect,parent=None):
qtgui.QGraphicsScene.__init__(self,rect,parent)
def mousePressEvent(self,event):
for item in self.items():
item.drawPoint(event.scenePos().x(),event.scenePos().y())
self.update()
app=qtgui.QApplication(sys.argv)
# create window
window=qtgui.QMainWindow()
window.show()
window.resize(240,240)
# set up scene and view
scene=CustomScene(qtcore.QRectF(0,0,200,200))
scene.setBackgroundBrush(qtgui.QBrush(qtgui.QColor(255,255,255)))
scene.update()
view=CustomGraphicsView(scene,window)
view.show()
window.setCentralWidget(view)
item=CustomItem(None,None)
item.view=view
scene.addItem(item)
app.exec_()
_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt