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. Rotate QImage around Y axis
Forum Updated to NodeBB v4.3 + New Features

Rotate QImage around Y axis

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 949 Views 2 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.
  • A Offline
    A Offline
    addebito
    wrote on last edited by
    #1

    Hi guys,
    I'd like to rotate an image around Y axis of point defined in the bottom right position of the image.

    Something like this...
    412d8e31-d0c2-4830-a6ce-5b12bd7e89e3-immagine.png

    I'm playing with QTransform but with strange results...
    Is the QTransform the correct approach?

    This is the code

      QTransform transform;
      transform.reset();
      //  transform.translate(-960, -960);
      transform.rotate(-m_rotation, Qt::YAxis);
      //  transform.translate(960, 960);
    
      QPainter painter(this);
      painter.save();
      painter.setTransform(transform);
      painter.drawImage(100, 100, srcImg);
      painter.restore();
    

    With this code I have some problems:

    • the rotation is around Y axis but on the left image
    • the rotation is made in a perspective view (eg: like this)

    16c59312-0d50-448f-82be-109b74b5a57d-immagine.png

    Thank you for any suggestion.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      In Qt origin is at the top left, not bottom right, and Y axis goes down, not up, so to rotate around the right border you have to move your transform by the width of the image. Since rotation uses perspective you also have to move the origin vertically to the center. Lastly you can't translate by 100,100 at the end. It's all in the order of transformations, so to achieve the effect you want it's something like this:

      QTransform transform;
      transform.translate(100,100);
      transform.translate(srcImg.width(), srcImg.height() / 2);
      transform.rotate(m_rotation, Qt::YAxis);
      transform.translate(-srcImg.width(), -srcImg.height() / 2);
      
      QPainter painter(this);
      painter.save();
      painter.setTransform(transform);
      painter.drawPixmap(0,0,srcImg);
      painter.restore();
      
      1 Reply Last reply
      4
      • A Offline
        A Offline
        addebito
        wrote on last edited by
        #3

        Thank you so much @Chris-Kawa

        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