PDA

View Full Version : rotate image in Qpainter



Parvat
5th June 2013, 12:44
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.


QPainter painter(this);

painter.setPen(Qt::yellow);
painter.setPen(Qt::DashDotDotLine);
QRectF rectangle( 10.0, 50.0, 400, 400 );
painter.drawRect( rectangle );
QRectF Rect( 10.0, 50.0, 400.0, 400 );
painter.rotate(90);
painter.drawImage( Rect, myImage );

anda_skoa
5th June 2013, 14:23
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,
_

Parvat
5th June 2013, 14:49
thanks i got that point of translating to center ,
but i want that rotated image to fit in the Rectangle size ...ne idea??