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. Have a problem with rotation of QGraphicsRectItem

Have a problem with rotation of QGraphicsRectItem

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 499 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.
  • B Offline
    B Offline
    BeastBook
    wrote on last edited by
    #1

    I created class MyRect that inhertis from QGraphicsRectItem and my goal is
    to rotate rect in center by 10 degree when user press left or right key but problem
    is that rect rotate only once after second press on key it wont and rotation is not in center of rect

    void MyRect::keyPressEvent(QKeyEvent *event)
    {

    if(event->key()==Qt::Key_Left)
    {
    
        setRotation(-10);
    
    
    
      // setPos(x()-10,y());
    
    }
    
    else if(event->key()==Qt::Key_Right)
    {
    
        setRotation(10);
       // setPos(x()+10,y());
    
    }
    

    }

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Because you're setting the rotation explicitly to +/- 10 degree as described in the documentation
      "Sets the clockwise rotation angle, in degrees, around the Z axis. The default value is 0 (i.e., the item is not rotated). Assigning a negative value will rotate the item counter-clockwise. "

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      B 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        Because you're setting the rotation explicitly to +/- 10 degree as described in the documentation
        "Sets the clockwise rotation angle, in degrees, around the Z axis. The default value is 0 (i.e., the item is not rotated). Assigning a negative value will rotate the item counter-clockwise. "

        B Offline
        B Offline
        BeastBook
        wrote on last edited by
        #3

        @Christian-Ehrlicher
        I find how to rotate with this setRotation(rotation()+10); now how to rotate in center of rect not of the top left corner and thank you

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          This also is described in the documentation two lines below ...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          B 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            This also is described in the documentation two lines below ...

            B Offline
            B Offline
            BeastBook
            wrote on last edited by
            #5

            @Christian-Ehrlicher Thank you i solve my problem with this
            setTransformOriginPoint(QPoint(50,50));
            setRotation(rotation()-10);

            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