0
votes

I am using QVBoxLayout to group widgets. When I add the widgets to the layout, there is some spacing between the widgets. How do I remove this spacing? I tried setting the margins to 0, and also used setSpacing(0) but to no effect. How can this be done?

1
if you set spacing to 0 and margin to 0, then that what you got is the most spaceless QVBoxLayout you can ever have. If it's still to much space between widgets, you have to try other way. - Blood
setSpacing(0) should be the correct method. Did you apply it to the correct layout? (Apply it to the "outer" layout, not another layout which is within the outer layout of which you want to remove the spacing.) - leemes
qt layouts are just stupid like that. Sometimes they do completely different thing from expected - BЈовић

1 Answers

0
votes

After changing spacing and margins, if the widget is already shown, you need to call adjustSize() on the widget or update(). There are also some minimum sizes built into widgets, too, that you should be aware of.

If you are just trying to get the layout to look right, I would use the Qt IDE form editor/ Design Mode, and drag and drop in the elements that you want, and turn on layouts as necessary. All the properties you would need to edit are visible in the lower right.