Solved Slicing QGraphicsItem
-
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 -
@Ilan said in Slicing QGraphicsItem:
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
Here is the code I trieddef 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() # scene bounding rect self.rect = self.charPath.boundingRect() self.rect = self.mapToScene(self.rect) self.rect = self.rect.boundingRect() self.rect.setWidth(self.rect.width() / self.dx) self.rect.setHeight(self.rect.height() / self.dy) def sceneBoundingRect(self): return self.rect
Thanks,
Ilan