[PyQt] Re: dragging a QGraphicsSvgItem

Matt Smith melkor at orangepalantir.org
Wed Mar 18 11:45:15 GMT 2009


On Wed, 2009-03-18 at 09:15 +0000, pyqt-request at riverbankcomputing.com
wrote:
> From: Wolfgang Rohdewald <wolfgang at rohdewald.de>
> Subject: [PyQt] dragging a QGraphicsSvgItem
> To: pyqt at riverbankcomputing.com
> Message-ID: <200903180430.09934.wolfgang at rohdewald.de>
> Content-Type: text/plain;  charset="us-ascii"
> 
> While dragging it, I want to see the whole image of the item move.
> What works is something like this:
> 
> (code goes into class Tile(QGraphicsSvgItem), def mousePressEvent)
> 
>             ...
>             pmapSize = self.tileset.tileSize.toSize()
>             if self.pixmap is None or self.pixmap.size() != pmapSize:
>                 self.pixmap = QPixmap(pmapSize)
>                 self.pixmap.fill(Qt.transparent)
>                 painter = QPainter(self.pixmap)
>                 QGraphicsSvgItem.paint(self, painter,
> QStyleOptionGraphicsItem())
>                 for item in self.childItems():
>                     QGraphicsSvgItem.paint(item, painter,
> QStyleOptionGraphicsItem())
>             drag.setPixmap(self.pixmap)
>             drag.setHotSpot(event.pos().toPoint())
> 
> 
> but I do not want to render a SVG that is already rendered 
> 
> Is there any way I can avoid rendering this item twice? Did I overlook
> a QGraphicsSvgItem method that would return its rendered pixmap?
> 
> 
> 
> -- 
> Wolfgang
I use a graphics scene and I never have to explicitly paint anything.
It seems like you could create a pixmap item when you load the svg then
you wouldn't have to render it again later.



More information about the PyQt mailing list