Results 1 to 1 of 1

Thread: rotating a transformed QGraphicsPixmapItem. not the QPixmap inside

  1. #1
    Join Date
    Apr 2010
    Posts
    25
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Lightbulb Re: rotating a transformed QGraphicsPixmapItem. not the QPixmap inside

    Hello,

    when I apply a rotation to a QGraphicsPixmapItem after a transform of it, the result is the QPixmap inside the Item gets rotated and then fit to the transform (which operates on the original position) which is a distortion instead of the transformed Item being rotated.
    Qt Code:
    1. QTransform::quadToQuad(QPolygonF(points),QPolygonF(points2),perspectiveMatrix);
    2. phone->setTransform(perspectiveMatrix);
    3. phone->setRotation(360*angle/6.28);
    To copy to clipboard, switch view to plain text mode 
    The perspectiveMatrix creates a trapezoid from a rectangle (so its a perspectived rectangle). This Matrix is dependent on the corners of the rectangle. It establishes a grid in which the original corners are projected to the destination corners. Other grid corners don't form the same shape in a perspective grid. Now the rotation rotates the original Pixmap away from the original corners and then the Pixmap is projected to some perspectived grid corners which are different than the destination corners as the original corners area different now thus the result is a deformed trapezoid.

    I like to have the transformed Item as a whole being rotated just like when you move and rotate a cut photograph on a desk it doesn't get distorted to having cuts at new positions inside the photo because there was the place of the cut on the desk but the photo remains intact when moving from A to B.

    I can understand what can cause this from a implementation standpoint but this is counterintuitive imo. Unfortunately Qt operates on the View or Scene layer as documented by the setTransformOriginPoint being in Scene/View coordinates rather than Item coordinates when wanting to set that point for the Item thus one always has to know every translation etc. rather than the Item carrying the point with it.

    If there is a way in Qt to achieve what I want, I'm going to be very joyful to read! (any hints and comments also welcome!)


    Added after 40 minutes:


    I found a solution:

    I can do the perspective transformation on the Pixmap itself and leave the rotation as the only transformation in the Item:
    Qt Code:
    1. phone->setPixmap((sms->pixmap()).transformed(perspectiveMatrix,Qt::SmoothTransformation).scaledToWidth(newwidth),Qt::SmoothTransformation));
    To copy to clipboard, switch view to plain text mode 

    Before, all transformations were applied to the Item coordinates. A functionality to rotate an Item inside a Scene just as the Origin is in scene coordinates would be helpful.

    If Qt has another solution I'm still glad to hear.

    My solution corrects for the in-pixmap transformation letting the pixmaps size remain untouched. As my perspectived rectangle is going to be wider I set the width accordingly.
    Last edited by planetLars; 15th February 2012 at 16:19. Reason: explaining the solution

Similar Threads

  1. QGraphicsPixmapItem to QPixmap to QImage and back again!
    By bruceariggs in forum Qt Programming
    Replies: 2
    Last Post: 10th September 2011, 14:08
  2. Rotating a pixmap inside a widget
    By Eneswar in forum Newbie
    Replies: 3
    Last Post: 3rd May 2011, 10:39
  3. Replies: 2
    Last Post: 15th March 2010, 10:03
  4. QPixmap Rotating but not translating
    By Qt Coder in forum Qt Programming
    Replies: 0
    Last Post: 8th April 2009, 10:40
  5. Replies: 2
    Last Post: 3rd November 2006, 22:20

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.