Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Slicing QGraphicsItem
Forum Updated to NodeBB v4.3 + New Features

Slicing QGraphicsItem

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 364 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Ilan
    wrote on last edited by
    #1

    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

    I 1 Reply Last reply
    0
    • I Ilan

      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

      I Offline
      I Offline
      Ilan
      wrote on last edited by
      #2

      @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 tried

      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()
              # 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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved