Firstly, I apologise for my ugly drawing skills. I have an application where i load 4 images of size 640x480in the QLabels as shown in the image. 
Letters V, H and G here mean Vertical, Horizontal and Grid layouts respectively.
Implemented sizeHint(), heightForWidth() and widthForHeight()for the QLabel. In the resizeEvent() of my QMainwindow i call setFixedWidth() on QLabelwhich solves the issue of fitting the size of QLabel to the image keeping the aspect ratio. I want to maintain the aspect ratio of the image at all times.
Issues:
- Setting a fixed width on
QLabelpushes the widget3 out of view in smaller resolution screens like my laptop.
I tried setting no fixed widths for the QLabel and tried to load the images keeping the aspect ratio. Size policy is set to expanding
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
I get something like this
Issues:
Loading the image while keeping the aspect ratio leads to unwanted expanding of QLabelbeyond the image horizontally which looks ugly.
What do i want:
QLabelshould fit to the image all the time irrespective of its own size.- There should not be any weird empty spaces between
widget1andQLabel - The whole application should fit on any resolution by changing the size of the
QLabelwhile keeping the aspect ratio of the image.
I feel it is kind of definition/design problem than being a technical problem. I tried all sorts of constraints and policies but couldn't achieve what i wanted. I believe i could get some suggestions here.

Aucun commentaire:
Enregistrer un commentaire