简体   繁体   中英

Qt Margin/spacing between widgets

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

Here is a picture that illustrate what I want:

在此输入图像描述

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,

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM