PDA

View Full Version : Layout Management Issues



dave
4th November 2006, 21:24
How can I control the space between layout and widgets inside a parent layout?

I have a QVBoxLayout. Inside there are a QLabel and a QGridLayout and another QLabel. As the widget start everything works fine. but when I change the widget size - QT put the all additional vertical space before and after the QGridLayout.

I think it happens because QVBoxLayout act towards the QGridLayout as if it is just another widget. So QVBoxLayout keeps same space between the three widget it has: QLabel, QGridLayout and QLabel.

My Question is: How do make it react to the widgets QGridLayout hosts? so I will have even spacing between all the widget in the form?

Thanks
Dave

wysota
5th November 2006, 14:53
I'm not sure what exactly the problem is. Could you provide a minimal compilable example which demonstrates the problem? Maybe the solution is to have a 0 margin in the child layout? This way only the parent layout and all the spacings would have an effect.

dave
5th November 2006, 15:22
I've given up on using both layout. Now I'm only using one grid layout. This is the code to set it up:

void LSysEdge::setupWidget()
{
title = new QLabel("LSystem\nEdge Rewriting Based");
title->setTextFormat(Qt::RichText);
title->setAlignment(Qt::AlignHCenter);

initL = new QLabel("&Initiator");
init = new QLineEdit();
initL->setBuddy(init);
init->setValidator(new LSEdgeValidator(init));

ruleFL = new QLabel("Production &F");
ruleF = new QLineEdit();
ruleFL->setBuddy(ruleF);
ruleF->setValidator(new LSEdgeValidator(ruleF));

rulefL = new QLabel("Production &f");
rulef = new QLineEdit();
rulefL->setBuddy(rulef);
rulef->setValidator(new LSEdgeValidator(rulef));

angleL = new QLabel("&Angle");
angle = new QLineEdit();
angleL->setBuddy(angle);
angle->setValidator(new QIntValidator(0, 90, angle));
angle->setMaximumWidth(20);

stepsL = new QLabel("&Steps");
steps = new QLineEdit();
stepsL->setBuddy(steps);
steps->setValidator(new QIntValidator(1, 9999, steps));
steps->setMaximumWidth(35);

create = new QPushButton("&Create");

connect(create, SIGNAL(clicked()),
this, SLOT(createClicked()));
}


void LSysEdge::setupLayouts()
{
mainLayout = new QGridLayout;

mainLayout->addWidget(title, 0, 0, 1, 4);

mainLayout->addWidget(initL, 1, 0, 1, 1);
mainLayout->addWidget(init, 1, 1, 1, 3);

mainLayout->addWidget(ruleFL, 2, 0, 1, 1);
mainLayout->addWidget(ruleF, 2, 1, 1, 3);

mainLayout->addWidget(rulefL, 3, 0, 1, 1);
mainLayout->addWidget(rulef, 3, 1, 1, 3);

mainLayout->addWidget(angleL, 4, 0);
mainLayout->addWidget(angle, 4, 1);

mainLayout->addWidget(stepsL, 5, 0);
mainLayout->addWidget(steps, 5, 1);

mainLayout->addWidget(create, 6, 1, 1, 1);

setLayout(mainLayout);

init->setFocus();
}

The problem is that if I try to resize the widget height, all the available space go between the first QLabel and all the other widgets. the space between all the other widgets don't change at all.

wysota
5th November 2006, 18:16
Then you probably have to use different size policies. Especially the one from the label.