Unsolved QLabel won't fit an image without margins
-
I create two labels on a vertical layout using Qt designer. The top label has a image and the lower label has text. For both labels, I right clicked > Layout Alignment > Center Horizontally, Top.
The problem I have is the top label which has the image has a big space separating it from the lower label. I selected it and then clicked geometry in the right panel, it expanded to show x, y, width, and height. The width x height is 327 x 78. The actual dimension of the image is 284 x 67. I can't modify the values because they are grayed out.
How can I eliminated the excess space in the label not used by the image so that the top and lower labels look as if they were almost one label without the big space separating them?
-
Hi
for the layout, check the layout margins.
there is also one that defines the space between widgets.
(layoutHorizontalSpaceng) -
layoutLeftMargin 0
layoutTopMargin 0
layoutRightMargin 0
layoutBottomMargin 0layoutSpacing 6
I changed the layoutSpacing to 0 saved and ran the app, still get the same result.
-
@mrjj said:
also layoutHorizontalSpacing ?
You could set Maximum Height on the label with image
to match image dimensions.can u show a picture ?
-
@WhatIf
Hello,
The label widget has a margin itself (the distance between the frame and the contents) that is independent of the layout's margins. Have you tried setting the label margin to be 0 as well?Kind regards.
-
I changed the height and width of maximumSize to that of the image dimensions and still I get the same result. When I select the label that has the image, I can't find a layoutHorizontalSpacing for it.
Here is the link to the result when I run the program:
-
QLabel margin is 0
-
@WhatIf
Have you put a vertical spacer at the bottom? If not the layout will always try to distribute the space between the widgets.