Results 1 to 5 of 5

Thread: slicing QGraphicsItem

  1. #1
    Join Date
    Jan 2017
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default slicing QGraphicsItem

    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
    Qt Code:
    1. def updateTransform(self):
    2. self.dx = self.boundingRect().width()/self.charPath.boundingRect().width()
    3. self.dy = self.boundingRect().height()/self.charPath.boundingRect().height()
    4. transform = self.transform()
    5. transform.scale(self.dx,self.dy)
    6. self.setTransform(transform)
    7. self.prepareGeometryChange()
    8. # here I want to set the new boundingRect
    9.  
    10. def boundingRect(self):
    11. return self.rect
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: slicing QGraphicsItem

    Quote Originally Posted by hindy.ilan@gmail.com View Post
    How can I set the item's boundaries to that of the enlarged QPainterPath
    Return it as the item's boundingRect.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2017
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: slicing QGraphicsItem

    I tried to return the bounding rect of the QPainterPath but it returned the bounding rect before the scale
    Ilan

  4. #4
    Join Date
    Jan 2017
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: slicing QGraphicsItem

    The solution was to use QGraphicsPathItem
    This item can contain QPainterPath and can be scaled and moved
    Ilan

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: slicing QGraphicsItem

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Help on QGraphicsItem::paint please
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2011, 09:11
  2. Replies: 7
    Last Post: 29th November 2010, 20:20
  3. Casting QGraphicsItem child from QGraphicsItem
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 29th August 2008, 16:37
  4. Replies: 2
    Last Post: 28th June 2008, 17:31
  5. resize a QGraphicsItem
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 29th April 2008, 10:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.