PDA

View Full Version : Qwidget resize delay problem



zl2k
9th November 2008, 00:19
hi, there
I am using the qwidget to display images which could be portrait or landscape and the widget is resized for the image size, everything looks fine except when I display a portrait after a landscape or vise versa , the widget becomes square. A second image of the same shape will turn the widget to the image's shape. For example, if I am showing portrait, landscape, landscape in a sequence, the widget will be portrait, square, landscape. How can I change the square to the shape of the image? Here is my code.



/* imageLabel, imageviewerLayout, and imageViewer are QLabel, QVBoxLayout and QWidget which are defined globally*/
QImage image(myFileName);
imageLabel->setPixmap(QPixmap::fromImage(image));
imageLabel->resize(image.size());
imageviewerLayout->update();
imageViewer->resize(image.size());
imageViewer->updateGeometry();
imageViewer->show();


Thanks for help and have a good weekend.
zl2k

h123
9th November 2008, 06:28
Hi,

you can try QWidget::adjustSize()

or

on portrait or landscape you r getting some signal, in its slot get the size of the image and set that size to QWidget.

Hope it will help.

zl2k
10th November 2008, 14:02
imageViewer->resize(image.size());
//imageViewer->updateGeometry();
imageViewer->adjustSize();

will do the job. If the updateGeometry() is there, it will still adjust the portrait/landscape. But, if I am showing a 400*200 after a 400*300 (both landscape), the size of the widget wont't be adjusted immediately. I still need a second 400*200. After removing the updateGeometry(), everything works fine now, thank you.
zl2k