4
votes

Using Qt, I've set up a main dialog with a horizontal layout. This horizontal layout contains three vertical layouts. I really want all controls in these layouts to butt right up against each other, but I can't get QT to remove all padding and spacing.

I've set the spacing, and padding on all layouts to 0, and I've used CSS to clear all borders, padding, and margins. I still cannot get rid of the darn spacing.

Here's an image of what it looks like:
Controls not pushed together.

As far as I can think, those widgets should be pushed up against that red line.

2
Just thinking out loud: If you have tried everything with the layouts, can you confirm that the widgets themselves don't have borders? In other words the layouts and widgets really are butting against each other, but visually there is a margin internal to the widget. - cmannett85
That is a great question. I can get the QPushButtons to bump right up to each other, but the Labels, and the Lists do not. Even when I set their margin, border, and padding to zero with css. Could I be missing something when it comes to removing those borders? - Murphy Randle
Small update, it seems that those borders between the list items goes away when I remove the buttons that I had in the layouts. Maybe the buttons are causing odd padding? - Murphy Randle

2 Answers

1
votes

Have you tried

layout->setContentsMargins(0,0,0,0);

... where layout is a pointer to a QVBoxLayout, QHBoxLayout, etc?

0
votes

For anyone with a similar problem try one of the following

layout->setContentsMargins(0,0,0,0);
layout->setSpacing(0);
layout->setMargin(0);