7

I'm trying to increase padding between widgets contained within a QMainWidget and the edges of the QMainWidget. You can see the problem in the image below:

Padding between edges

There is no padding between QTabWidget (which is central widget of the QMainWidget) and the left edge of the main window. Also there is no padding between QDockWidgets and the right edge of the main window.

I tried to increase padding with QSS stylesheet:

QMainWindow {
    padding: 10px;
    margin: 10px;
    border: 5px solid red;
}

but got some really unexpected result:

Unexpected result

I tried calling setContentsMargins method, but it actually changes the margins around the central widget just as the method's name says.

How can I increse padding between QMainWindow and contained widgets? Is there a way to change it with QSS?

ezpresso
  • 7,896
  • 13
  • 62
  • 94
  • 2
    Easy fix would be to set a plain `QWidget` as the central widget and set `contentsMargins` to the widget's layout. Then just add your `QTabWidget` to the widget's layout. – thuga Jan 14 '15 at 08:36
  • 1
    @ezpresso did you ever solve this? I'm having the same problem – Supamee Jul 24 '17 at 12:34

1 Answers1

1

You would need to put them all in another container and then set that container to be the central widget. Then you can call container.setContentsMargins()

Supamee
  • 615
  • 5
  • 15