Ivan Akulov
Ivan Akulov

Reputation: 4323

Removing extra spacing around QWidget

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.

Upvotes: 10

Views: 17606

Answers (2)

Morten Kristensen
Morten Kristensen

Reputation: 7613

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().

Upvotes: 23

tsragravorogh
tsragravorogh

Reputation: 3153

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)

Upvotes: 3

Related Questions