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 590 Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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

      ? 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

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

        ? Offline
        ? Offline
        A Former User
        wrote on 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

        • Login

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