mercredi 4 septembre 2019

Layout design issue with Qt application

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. 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:

  1. Setting a fixed width on QLabel pushes 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

image2

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:

  1. QLabel should fit to the image all the time irrespective of its own size.
  2. There should not be any weird empty spaces between widget1 and QLabel
  3. The whole application should fit on any resolution by changing the size of the QLabel while 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