PDA

View Full Version : Problem with displaying image using Qlabel



deck99
19th March 2011, 05:34
Hi........
I have a problem while displaying an image in label. when u simply open l.png its image display is horizontal but when u open with code display is in vertical. i want the image as it is seen in simply opening and no scrollbar should come full image should be displayed on the label with no scollbars.


imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ig nored);
imageLabel->setScaledContents(true);

scrollArea = new QScrollArea;
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setWidget(imageLabel);
setCentralWidget(scrollArea);

setWindowTitle(tr("Image Viewer"));
resize(800, 900);

QImage image("/home/karl/Desktop/l.tif");


imageLabel->setPixmap(QPixmap::fromImage(image));

scaleFactor = 1.0;

scrollArea->setWidgetResizable(1);

JohannesMunk
20th March 2011, 00:23
I dont quite understand! If you don't want scrollbars, then don't put your label into a scrollarea. setScaledContents should scale your pixmap to fit the labels size.

As to the rotation: Could it be that your image viewer automatically rotates the file due to some meta information e.g. xmp or exif orientation? Because I don't think that QLabel will rotate the image by itself.

Try an image from a different source.

HIH

Joh