Removing Extra Spacing Around QWidget

How to remove extra spacing around QWidget?

Here is a simple example. Widget - gray; you see, there is some kind of space (about 0.3-0.4 cm) around its contents (image, text and button).

Widget space highlighted

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

Example

Here is the content (highlighted when running setStyleSheet( "background-color: red"); for the entire widget.

Example

"Removing the extra interval" I mean removing about gray space about 0.2-0.3 cm around the contents.

+6
source share
1 answer

Change the content fields of the layout to which you added the QWidget and any other layout that you want to change using the setContentsMargins() method.

+14
source

Source: https://habr.com/ru/post/923173/


All Articles