PDA

View Full Version : rotate a QPixmap which is set on top of a QLabel



rishiraj
19th January 2009, 12:36
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---

int count=0;
void pic_dis::rotate()
{
count++;
QPixmap pm1 = QPixmap(fileName); //fileName is the complete path to the
//picture
//which I need to rotate
QMatrix m1 ;
m1.rotate( (90*count)%360 );
if(count%2==1)
{
m1.scale((double)420/pm1.width(),
(double)750/pm1.height());
}
else
m1.scale((double)750/pm1.width(),
(double)420/pm1.height());
pm1 = pm1.xForm(m1);
pic_display->setPixmap(pm1);
}

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.

wysota
19th January 2009, 15:35
Have a look at QPixmap::transformed().

rishiraj
20th January 2009, 08:13
Thank you.Your suggestion worked.
****in case anyone's having the same problem as I was having,I am pasting the working code below********

int count =0; //count keeps track of the number of times you click thw rotate button
void ImageViewer::rotate() //slot which is called on clicking rotate
{
count++;
QPixmap pm=QPixmap(fileName); //fileName is the picture that you are displaying
QMatrix mat;
mat.rotate((90*count)%360); //rotation operation
if(count%2==1) //code which rotates pic by 90,180,360 depending on the number
//of times you click 'rotate'
{
mat.scale((double)420/pm.width(),(double)750/pm.height());
}
else
mat.scale((double)750/pm.width(),(double)420/pm.height());
QPixmap pm1=pm.transformed(mat); //saving the changed QPixmap in a new QPixmap
imageLabel->setPixmap(pm1); //setting changed Pixmap on the label

}