[Solved] Python QPixmap positioning?
-
Hi,
I'm trying to change the position of a pixmap, but it doesn't seem to be working:
@iconview = QtGui.QGraphicsView()
scn = QtGui.QGraphicsScene(iconView)
scn.setSceneRect(iconView.sceneRect())
iconView.setScene(scn)
pix = QtGui.QPixmap("picture.xpm")
item = QtGui.QGraphicsPixmapItem(scn.addPixmap(pix))
item.setPos(0, 30) # for ex@It displays the picture, but doesn't move the position...just stays in the center.
Thanks!!
-
Any ideas?
Thanks!!
-
Your problem is with the following line:
@scn.setSceneRect(iconView.sceneRect())@
If you print out the result of sceneRect() you get:
@QRectF(0.0, 0.0, 0.0, 0.0)@
i.e. a rectangle of no size. This is because the QGraphicsView doesn't have a scene from which to get a size yet so returns default. If you set a size as follows your icon will be placed as desired:
@scn.setSceneRect(QRectF(0.0, 0.0, 250.0, 250.0))@
-
Thanks again, jazzycamel!!! :)