Results 1 to 3 of 3

Thread: rotate image in Qpainter

  1. #1
    Join Date
    May 2013
    Location
    Mumbai
    Posts
    11
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Question rotate image in Qpainter

    I want to rotate a particular image that is drawn in QRectf this my code ,I DO GET THE IMAGE but when i try to rotate it gets rotate outside the rectangle.
    help me out guys.

    Qt Code:
    1. QPainter painter(this);
    2.  
    3. painter.setPen(Qt::yellow);
    4. painter.setPen(Qt::DashDotDotLine);
    5. QRectF rectangle( 10.0, 50.0, 400, 400 );
    6. painter.drawRect( rectangle );
    7. QRectF Rect( 10.0, 50.0, 400.0, 400 );
    8. painter.rotate(90);
    9. painter.drawImage( Rect, myImage );
    To copy to clipboard, switch view to plain text mode 
    Last edited by Parvat; 5th June 2013 at 12:10.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: rotate image in Qpainter

    QPainter::rotate() used (0,0) as the rotation anchor. If you want to rotate around the center of the rectange than you have to first translate into the center, then rotate.
    resetTransform() when you're done.

    Alternatively you can prepare a QTransform object that contains those two transformations, set it before drawing the image.

    Cheers,
    _

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

    Parvat (5th June 2013)

  4. #3
    Join Date
    May 2013
    Location
    Mumbai
    Posts
    11
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: rotate image in Qpainter

    thanks i got that point of translating to center ,
    but i want that rotated image to fit in the Rectangle size ...ne idea??

Similar Threads

  1. QPainter::rotate and Qwt problems
    By alex_sh in forum Qwt
    Replies: 2
    Last Post: 20th October 2011, 17:44
  2. Qt3-QPainter rotate exception
    By Raccoon29 in forum Qt Programming
    Replies: 4
    Last Post: 4th September 2007, 17:43
  3. Replies: 3
    Last Post: 14th March 2007, 08:09
  4. Replies: 3
    Last Post: 30th April 2006, 19:22
  5. QPainter rotate function
    By ir210 in forum Newbie
    Replies: 3
    Last Post: 17th January 2006, 04: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
  •  
Qt is a trademark of The Qt Company.