PDA

View Full Version : slicing QGraphicsItem



hindy.ilan@gmail.com
15th April 2017, 08:44
Hi,
I have an item inherited from QGraphicsItem
I draw in the item (using QPainterPath)
Then I want to do 2 things:
Scale the item so that the QPainterPath boundaries will have the item size
Resize the item to the original size so that it will include only the QPainterPath
I managed to do the first mission using transform
How can I set the item's boundaries to that of the enlarged QPainterPath

def updateTransform(self):
self.dx = self.boundingRect().width()/self.charPath.boundingRect().width()
self.dy = self.boundingRect().height()/self.charPath.boundingRect().height()
transform = self.transform()
transform.scale(self.dx,self.dy)
self.setTransform(transform)
self.prepareGeometryChange()
# here I want to set the new boundingRect

def boundingRect(self):
return self.rect

wysota
15th April 2017, 11:05
How can I set the item's boundaries to that of the enlarged QPainterPath
Return it as the item's boundingRect.

hindy.ilan@gmail.com
15th April 2017, 11:30
I tried to return the bounding rect of the QPainterPath but it returned the bounding rect before the scale
Ilan

hindy.ilan@gmail.com
16th April 2017, 11:35
The solution was to use QGraphicsPathItem
This item can contain QPainterPath and can be scaled and moved
Ilan

wysota
17th April 2017, 16:06
Transforms are external to the item - they take the item (including its bounding rect) and transform that. If you want to scale the path "internal" to the item, you should do that in the item itself (e.g. its paint() routing) and take that into consideration when returning the bounding rectangle.