2
votes

I have a QLabel and a QPushButton added to a QHBoxLayout. The QLabel has its margins set to 0 and the layout has margin and content margins set to 0. The label and button have the same background color and the button has border set to none. However, the button still looks with a brighter color than the label and there is some extra space around the button, so it doesn't look like it's "glued" to the label. I want them to look like one big widget.

2
If this problem is reproducible on Windows with Aero theme, please try to switch to Classic theme and let us know what do you see.Ilya
I am on Debian Jessieulak blade
@Ilya there seems to be slight space between the label and the button, but I don't know why, I've set anything related to margin on both widgets and the layout to 0ulak blade
Ok, thank you for this additional info. Could you add screenshot and your code which creates all these widgets? What is your Qt version?Ilya

2 Answers

2
votes

In Qt, margins describe the space surrounding the layout. In newer versions of Qt, the margins on the top/bottom/left/right can be set individually through setContentsMargins().

The space between widgets in the same layout is described by the spacing property. The spacing has nothing to do with the margins. Try calling hboxLayout->setSpacing(0); This should work.

0
votes

Some days ago I have coded a widget with similar behavior. To avoid problems with margins and colors I can recommend to use second QPushButton button instead of QLabel and set both buttons to be flat with btn->setFlat(true);