Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Reimplement QGraphicsItem setRotation and setScale methods with QTransform

Reimplement QGraphicsItem setRotation and setScale methods with QTransform

Scheduled Pinned Locked Moved Unsolved Qt for Python
qt for pythonpython
3 Posts 2 Posters 211 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.
  • K Offline
    K Offline
    ktechhydle
    wrote on 21 Nov 2024, 03:23 last edited by
    #1

    Hello all. I am trying to reimplement the setRotation and setScale methods of my qgraphicsitem with a QTransform.

    So far, I have this:

        def setRotation(self, angle):
            self._rotation = angle
            self.updateTransform()
    
        def setScale(self, scale):
            self._scale = scale
            self.updateTransform()
    
        def rotation(self):
            return self._rotation
    
        def scale(self):
            return self._scale
    
        def updateTransform(self):
            # Compute the custom transformation
            transform = self.transform()
            transform.translate(self.boundingRect().center().x(), self.boundingRect().center().y())
            transform.rotate(self._rotation)
            transform.scale(self._scale, self._scale)
            transform.translate(-self.boundingRect().center().x(), -self.boundingRect().center().y())
            self.setTransform(transform)
    

    The major issue is how the transforms stack on top of each other, causing the problem where trying to reset the rotation/scale to 0 doesn't change anything. This means if I rotate the item to 45 and try to then rotate it back to 0, nothing happens because the item transform is already at 0 for rotation.

    Any help is greatly appreciated.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 21 Nov 2024, 06:52 last edited by
      #2

      Hi,

      As silly as it may sound: why not start from a fresh transform ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply 21 Nov 2024, 14:29
      0
      • S SGaist
        21 Nov 2024, 06:52

        Hi,

        As silly as it may sound: why not start from a fresh transform ?

        K Offline
        K Offline
        ktechhydle
        wrote on 21 Nov 2024, 14:29 last edited by
        #3

        @SGaist
        The problem with doing that is that it will reset the current transform, defeating the purpose of scaling/rotating the item.

        1 Reply Last reply
        0

        3/3

        21 Nov 2024, 14:29

        • Login

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