سؤال

I am having a label set from a pixmap as follow:

QLabel* label_image;
label_image= new QLabel (this);
label_image->setGeometry(0, 0, 500, 30);

QPixmap pm;
pm ...
label_image->setPixmap(pm);

I would like now to rotate it by 90 degrees. How to do so?

هل كانت مفيدة؟

المحلول

You have two options here. The first is to subclass QLabel and provide the rotation functionality that you require. Alternatively, you can use QTransform to rotate the QPixmap that you set on the QLabel.

Rather than regurgitating the answer, this link explains how to do the rotation and maintain the original size of the image.


Update due to invalid link...

Essentially, you can't rotate the actual label, but you can rotate the pixmap, then set this on the label widget

QPixmap pm;
...
QTransform trans;
trans.rotate(90);

label_image->setPixmap(pm.transformed(trans));

If you keep rotating the same image, it will distort, so ensure any rotation is always from a stored, non-rotated pixmap.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top