Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Margin/spacing between widgets

Tags:

c++

layout

qt

I would like to manage the space between my widgets, verticaly and horizontaly.

Here is a picture that illustrate what I want:

enter image description here

When I click on the red point, I want to reduce/extend the spaces where the red lines are (vertically).

When I click on the blue point, I want to reduce/extend the spaces where the blue lines are (horizontally).

My architecture is like that:

A main Widget with a layout, which contains the left/right arrow buttons and a QWidget for all the white views.

This QWidget contains a QGridLayout. In this QGridLayout I have the "left", "back"... widgets (in white on the screenshot).

  • QWidget with a layout
    • left arrow
    • right arrow
    • QWidget with a QGridLayout (GRIDLAYOUT)
      • QWidget with a VBoxLayout and 2 labels inside. (VIEW)

I tried to set the VIEW->setContentsMargins(); but the white rectangle stay the same, only the spacing inside this rectangle change (between the border and the "left" label for example (1 and 2 on the screen)).

I also tried to set the GRIDLAYOUT->setContentsMargins(); but this time only the the spacing of number 3 and 4 on the screen are changing.

Obviously there is the same behaviour for the horizontal resizing. (the blue marks on the screenshot.

The spacing doesn't allow to manage vertical and horizontal spacing separately...

I hope that you understand what I try to explain :o

How can I manage this ?

Thank you in advance,

like image 736
Slot Avatar asked Jan 19 '15 09:01

Slot


1 Answers

For managing the space inbetween the white rects you can easily use

QGridLayout()::setHorizontalSpacing(int spacing);
QGridLayout()::setVerticalSpacing(int spacing);

This will set up the space between the white rects but not the space between white rect and border of upper widget. For these you will have to use (inherited from QLayout):

QGridLayout()::setContentsMargins ( int left, int top, int right, int bottom )
like image 64
Sebastian Lange Avatar answered Sep 21 '22 16:09

Sebastian Lange