2

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.

4
  • 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. Commented Aug 12, 2015 at 10:48
  • I am on Debian Jessie Commented Aug 12, 2015 at 11:16
  • @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 0 Commented Aug 12, 2015 at 11:18
  • Ok, thank you for this additional info. Could you add screenshot and your code which creates all these widgets? What is your Qt version? Commented Aug 12, 2015 at 11:52

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

All set and still, there is margin. styleSheet-margin destroys the layout
0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.