Unwanted vertical padding with QComboBox in nested layout
I'm using QtCreator 3.6.0 with Qt 5.4 on OsX. In the designer, I have a roughly 9 x 6 cell QGridLayout full of check boxes, combos and lineEdits. If I put a stacked widget or horizontal layout in one of the cells, and put a comboBox inside the stacked widget or horizontal layout, the whole QGridLayout row gets additional vertical padding. (The comboBox alone in the same QGridLayout cell doesn't cause the extra vertical padding.)
I've tried setting all the stacked widget or horizontal layout margins and spacing to 0, but to no effect.
Can anyone help?
You have to consult the Layout section of your widget and set its "LayoutLeftMargin" ... "LayoutVerticalSpacing" properties. By default, these values are 9 for the margins and 6 for the spacing.
This section is visible at the very end of the properties (right bottom window, in pink). Sometimes you have to click on another widget and click back on your first widget in order to make this Layout section appear.
Tell me if it's clear enough to locate this Layout section, otherwise I'll provide you with some screen shots.
Thanks for the reply.
Yep, I already found and adjusted the layout section of both the QGridLayout and any other layouts I placed in QGridLayout cells.
Here are some more details which should hopefully be reproducible.
I have the QGridLayout set to layoutHorizontalSpacing = 2 and layoutVerticalSpacing = 2. I have checkboxes in the 1st column, combo boxes in the 2nd and 3rd columns and lineEdits in 4th, 5th and 6th columnns. This works as expected in that the row height/spacing looks correct.
When I replace one of the line edits with, for example, a QHBoxLayout, the QHBoxLayout already has all margins set to 0 and layoutSpacing set to -1. If I build and run without anything added inside the QHBoxLayout, the QGridLayout row height/spacing stays fine.
When I then add a QComboBox into the QHBoxLayout, the QGridLayout row height/spacing gets larger just for that row, even though there are other QComboBoxes in other cells in the same QGridLayout row. Changing the QHBoxLayout layoutSpacing from -1 to 0 doesn't do anything.
In place of the QHBoxLayout, I've also tried QStackedWidget and I get the same problem.
Can anyone else help with this padding problem?
Maybe posting before and after pictures will better demonstrate the problem.
Here's the QGridLayout without any nested layouts. It just has some basic controls and nothing in the right column.
The QGridLayout horizontal and vertical spacings are both set to 0.
Here's the same QGridLayout now with QStackedWidgets in the right column and where each stack has two pages, one with a line edit and one with a combo.
Note the increase in vertical spacing. (All the QStackedWidgets have margins and h and v layout spacings set to 0.)
Here's another pic of the QGridLayout with the QStackedWidgets in the right column, but this time with some combo pages showing. It has the same problem as the 2nd pic above.
The same problem occurs if the QStackedWidgets are replaced with H or V layouts. Either way, QT adds more spacing which I cant remove.
Did you try to remove margin in each QStackedWidget page?
Also, could you provide us with your ui file, so we can play with it?
Yes. The pics above have all the margins and layout spacings in all the stacked widgets pages set to 0.
Here's an example ui file and screen grab.
BTW It appears that this is a problem on Mac only. On Windows (using QT Creator w MSVC2013) the layout follows the designer settings and verticalSpacing=0 actually gives NO vertical gap for the cases/examples described above.
Could someone try the UI file I posted? Thanks.