Removing extra spacing around QWidget
Asked Answered
C

2

10

How to remove extra spacing around QWidget?

Here's the simple example. The widget's space is grey; you see, there's some space (about 0.3-0.4 cm) around the content of it (image, text and button).

Widget's space was highlighted by

setAutoFillBackground(true);
QPalette pal(palette());
pal.setColor(QPalette::Background, QColor("#e5e5e5"));
setPalette(pal);

Example

Here's the content (highlighted by running setStyleSheet( "background-color: red"); for the whole widget.

Example

By 'removing extra spacing' I mean removing about 0.2-0.3 cm of grey space around content.

Chipman answered 18/8, 2012 at 10:25 Comment(0)
F
23

Change the contents margins of the layout you added the QWidget to and any other layout you wish to change by using the method setContentsMargins().

Faucher answered 18/8, 2012 at 10:29 Comment(0)
R
3

There are two functions that you can use to get rid of all the spacing in your layout:

  1. QLayout::setMargin(0)
  2. QLayout::setSpacing(0)
Reheat answered 9/8, 2018 at 23:53 Comment(1)
Even though ::setMargin() is obsolete, I still like using it cause of its convenience:)Reheat

© 2022 - 2024 — McMap. All rights reserved.