Results 1 to 3 of 3

Thread: rotate a QPixmap which is set on top of a QLabel

  1. #1
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Post rotate a QPixmap which is set on top of a QLabel

    Hi,
    I can't figure out how to rotate a picture which is set on top of a Label(in Qt 4.4.3)
    In Qt 3.3,I did it this way---
    Qt Code:
    1. int count=0;
    2. void pic_dis::rotate()
    3. {
    4. count++;
    5. QPixmap pm1 = QPixmap(fileName); //fileName is the complete path to the
    6. //picture
    7. //which I need to rotate
    8. QMatrix m1 ;
    9. m1.rotate( (90*count)%360 );
    10. if(count%2==1)
    11. {
    12. m1.scale((double)420/pm1.width(),
    13. (double)750/pm1.height());
    14. }
    15. else
    16. m1.scale((double)750/pm1.width(),
    17. (double)420/pm1.height());
    18. pm1 = pm1.xForm(m1);
    19. pic_display->setPixmap(pm1);
    20. }
    To copy to clipboard, switch view to plain text mode 
    xForm isn't available in Qt 4.4.3.

    Please suggest on what changes I should make in the code to make it work in Qt 4.4.3.
    Thanks for your time.
    Last edited by jpn; 23rd January 2009 at 16:16. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: rotate a QPixmap which is set on top of a QLabel

    Have a look at QPixmap::transformed().

  3. The following user says thank you to wysota for this useful post:

    rishiraj (20th January 2009)

  4. #3
    Join Date
    Dec 2008
    Location
    My spaceship needs repairs..so, I am stuck on beautiful earth
    Posts
    98
    Thanks
    25
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: rotate a QPixmap which is set on top of a QLabel

    Thank you.Your suggestion worked.
    ****in case anyone's having the same problem as I was having,I am pasting the working code below********
    Qt Code:
    1. int count =0; //count keeps track of the number of times you click thw rotate button
    2. void ImageViewer::rotate() //slot which is called on clicking rotate
    3. {
    4. count++;
    5. QPixmap pm=QPixmap(fileName); //fileName is the picture that you are displaying
    6. QMatrix mat;
    7. mat.rotate((90*count)%360); //rotation operation
    8. if(count%2==1) //code which rotates pic by 90,180,360 depending on the number
    9. //of times you click 'rotate'
    10. {
    11. mat.scale((double)420/pm.width(),(double)750/pm.height());
    12. }
    13. else
    14. mat.scale((double)750/pm.width(),(double)420/pm.height());
    15. QPixmap pm1=pm.transformed(mat); //saving the changed QPixmap in a new QPixmap
    16. imageLabel->setPixmap(pm1); //setting changed Pixmap on the label
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 20th January 2009 at 07:53. Reason: missing [code] tags

Similar Threads

  1. Trouble with QLabel
    By dany_MB in forum Newbie
    Replies: 3
    Last Post: 14th August 2009, 08:21
  2. Replies: 3
    Last Post: 17th July 2008, 07:43
  3. Rotate QLabel
    By shader76 in forum Newbie
    Replies: 9
    Last Post: 24th December 2007, 12:31
  4. paintEvent, QString to QPixmap, QLabel
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2007, 13:04
  5. QPixmap and HBITMAP
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 16:24

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.