简体   繁体   English

QLabel旋转

[英]QLabel rotation

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. 我现在想将其旋转90度。 How to do so? 怎么做?

You have two options here. 您在这里有两个选择。 The first is to subclass QLabel and provide the rotation functionality that you require. 首先是将QLabel子类化,并提供所需的旋转功能。 Alternatively, you can use QTransform to rotate the QPixmap that you set on the QLabel. 另外,您可以使用QTransform旋转在QLabel上设置的QPixmap。

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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM