PDA

View Full Version : Handle Spacing on Gridlayout with hidden elements



PeterSilie
18th August 2017, 09:14
Hello,

I am using a GridLayout (QT 4.8.7) and on certain actions i hide/show parts inside this layout using .hide()/.show().



The Problem which now occurs is that the spacing of these hidden elements is still shown inside the layout (see picture).

12563


layout = new QGridLayout( this );
layout->setMargin( 1 );
layout->setSpacing( 1 );

setSizePolicy( sizePolicy().horizontalPolicy(), QSizePolicy::Fixed );

Is there a simple way to prevent this behaviour?

d_stranz
18th August 2017, 16:57
This is controlled by several settings. First is horizontalSpacing(), then columnMinimumWidth(), and possibly columnStretch(). You may also need to play with the minimumSize() of the widgets you put in the column that become hidden.

PeterSilie
21st August 2017, 10:31
Well,

it is the vertical spacing.

Is there any way to set the vertical spacing in the gridlayout for a specific row?

Cause i'd like to keep the spacing on the shown rows but remove it from the hidden ones.

d_stranz
21st August 2017, 21:44
Maybe you need a different strategy. If the relationship between the "certain actions" and the rows / columns that are hidden or shown in the view is well-defined (e.g., for action "X", rows 1 - 3 are always hidden, for action "Y", they are always shown) then you might be better off using different widgets laid out specifically for each action and putting them into a QStackedWidget or QStackedLayout and showing whichever one is appropriate. Each widget in the stack contains only that which is needed for the purpose.