Rotate an QLabel
-
@CptN3m0
Hi
Yes, you can paint to a pixmap and set that to QLabel.QPixmap pix(500,500); QPainter paint (&pix); .. rotate and draw text.. label->addPixmap(pix);
-
Hi,
Or you can use QImage::transformed passing it a rotation matrix.
-
Okey I found a solution for me
QPixmap pixmap(*ui->label->pixmap()); QMatrix rm; rm.rotate(50); pixmap = pixmap.transformed(rm); ui->label->setPixmap(pixmap);
but the problem ist now, Im trying to draw the pixmap every time at the different rotate which was saved at mine vector. what is happening, it´s just rotate further
-
@CptN3m0
Well the normal solution is to keep the original unrotated bitmap and
assign a copy to the label. Then when new rotate is need , the original image is used
and not the already rotated version.You can also rotate it back, and rotate to a new angle but that often
distorts the image slowly. -
Hi,
Where does your QPixmap come from in the first place ?
-
@CptN3m0
Wait i just realized. you are just doing it to rotate text right ?
Not the actual image ?
So only the text matters. so u can just clear it and redraw text.QPixmap pixmap(*ui->label->pixmap());
pixmap.fill( Qr::red ); // just clear old
QMatrix rm;
rm.rotate(50);
pixmap = pixmap.transformed(rm);
...drawtext..
ui->label->setPixmap(pixmap); -
@CptN3m0
So you have 2.png in a resource file ?
alo, the goal is to rotate text, so the image has nothing u want to show. Just used to draw the text on ? -
@CptN3m0
Ok, so the the goal is to rotate 2.png ? and not text.
Anyhow, just add a QPixmap to .h and save the
2.png to it.
Then when you rotate always use the copy and not the already rotated one.
13/14