Results 1 to 8 of 8

Thread: Rotate QGraphicsPixmapItem

  1. #1
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Rotate QGraphicsPixmapItem

    Okay, I've been sitting on this issue for at least 4 hours now and just am exhausted.
    I'm trying to simply rotate a QGraphicsPixmapItem by 45° around its own axis.

    Qt Code:
    1. MyPixmap::MyPixmap() : QGraphicsPixmapItem()
    2. {
    3. this->setPixmap(QPixmap("wallpaper.jpg"));
    4.  
    5. QTransform t = this->transform();
    6.  
    7. t.translate(this->pixmap().width()/2, this->pixmap().height()/2);
    8. t.rotate(45, Qt::XAxis);
    9. t.translate(-this->pixmap().width()/2, -this->pixmap().height()/2);
    10.  
    11. this->setTransform(t);
    12. }
    To copy to clipboard, switch view to plain text mode 
    I tried alot of other options but the image is always moving around the whole screen and this is what comes out:



    Shouldn't the lower edge be large and the upper edge small, like a trapezoid? Anyway, that's what I want it to be but it seems like I'm missing something here

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate QGraphicsPixmapItem

    Why not use QGraphicsItem::rotate()?
    You can also do translations with the QGraphicsPixmapItem::translate();

    Be careful:
    this->pixamp->width() and height() are in local item coordinates.
    You should use boundingRect() and translate to scene coords, and make the rotation from the scene, not from the item...

  3. #3
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Rotate QGraphicsPixmapItem

    QGraphicsItem::rotate() only accepts one parameter (the degrees), so I can't find a way to tell it on which axis I want to rotate it on.

    And from translate() doc:
    Translates the current item transformation by (dx, dy).

    So I think the local item coods are enough.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Rotate QGraphicsPixmapItem

    Maybe this article will help?
    J-P Nurmi

  5. #5
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Rotate QGraphicsPixmapItem

    Thank you jpn, but I've already read that article and tried lots of examples from TT Labs but they all only work for the usual Z-Axis (which is not a problem and not really hard).

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate QGraphicsPixmapItem

    The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
    Keyword: 2D.

    I believe you'll have to do more computations than that to get a rotation around X. Like obtaining a projection on XY plane of the rotated image rect and then map the image on the resulting shape. Then you'll get a trapezoid.

  7. #7
    Join Date
    Oct 2006
    Location
    Germany
    Posts
    84
    Thanks
    5
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Rotate QGraphicsPixmapItem

    Well, I know. But I assumed since it also just uses QPainter with QTransform that wouldn't be a problem.
    TT Labs also created examples to achieve that:


    I looked into it but they all don't use QGraphicsView, they just use QWidget and paint the items on it with QPainter and QTransform (with similar code to mine above).

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Rotate QGraphicsPixmapItem

    Are you sure they don't do any extra things to the pixmaps once they have the transforms?

Similar Threads

  1. Rotate QLabel
    By shader76 in forum Newbie
    Replies: 9
    Last Post: 24th December 2007, 13:31
  2. GraphicsView rotate problem
    By forrestfsu in forum Qt Programming
    Replies: 7
    Last Post: 21st November 2007, 21:20
  3. QPolygon rotate
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2007, 12:18
  4. Can QPicture scale and rotate ?
    By igor in forum Qt Programming
    Replies: 6
    Last Post: 25th January 2007, 23:48
  5. QPainter rotate function
    By ir210 in forum Newbie
    Replies: 3
    Last Post: 17th January 2006, 05:31

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.