2

The problem is pretty simple. I have a QLabel object which gets a picture via setting a resource to the pixmap attribute. Because the Qt Designer is the best GUI Designer of the world (ever) it shows the picture rotated 90° left:

QLabel which I want to rotate

How can I rotate the QLabel?

I also would be happy if somebody could tell me why the Qt Creator does rotate the image itself. Windows (the best OS ever) says it has a width of 88 px and a height of 923 px:

Here Breite == Width and Höhe == Height (Höhe, Breite is German (Best language ever)):

Width and Height

I appreciate your help!

goulashsoup
  • 2,639
  • 2
  • 34
  • 60

2 Answers2

2

If I were you I would rotate the image and then set the label pixmap. Possibly not the best solution, but it works.

To rotate the image you could do something like this:

QPixmap original;
// load original from your source or take it from somewhere
QImage srcImg = original.toImage();
QPoint center = srcImg.rect().center();
QMatrix matrix;
matrix.translate(center.x(), center.y());
matrix.rotate(90);
QImage dstImg = srcImage.transformed(matrix);
QPixmap dstPix = QPixmap::fromImage(dstImg); //New pixmap rotated

Now you have the new QPixmap rotated ready to be set as the QLabel pixmap.

If you have the original image on your computer an even dumber and easier solution would be to rotate the original image with any image software and directly load it.

QPixmap verticalPixmap('/path/to/image/rotatedImage.jpg');
Nishi
  • 10,634
  • 3
  • 27
  • 36
Luca Angioloni
  • 2,243
  • 2
  • 19
  • 28
  • Thx... What I did not mention was that I actually rotated the image with _Paint_ but unfortunately Qt put it in like the original.... I actually had to copy the picture. – goulashsoup Feb 19 '17 at 11:46
0

It is necessary to copy the picture after rotating it because the Qt Creator will (why ever) not adopt the rotation...

goulashsoup
  • 2,639
  • 2
  • 34
  • 60