petwoip
7th March 2011, 21:30
I've been trying to make a QVBoxLayout act like a QFormLayout so that when I add widgets to the QVBoxLayout, they do not stretch across the length of the parent widget. I've been trying to do this with sizePolicies, sretchFactors, etc, but I can't seem to figure it out.
Here's my code:
QPushButton* thing1 = new QPushButton(QObject::tr("Hi"));
QPushButton* thing2 = new QPushButton(QObject::tr("There"));
QPushButton* thing3 = new QPushButton(QObject::tr("Again"));
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(thing1);
layout->addWidget(thing2);
layout->addWidget(thing3);
QWidget* widget = new QWidget();
widget->resize(300,300);
widget->setLayout(layout);
widget->show();
Output using a QFormLayout:
http://i.imgur.com/nWI28.png
Output using a QVBoxLayout:
http://i.imgur.com/lq0oX.png
I'd like the QVBoxLayout version to mimic the QFormLayout version.
Here's my code:
QPushButton* thing1 = new QPushButton(QObject::tr("Hi"));
QPushButton* thing2 = new QPushButton(QObject::tr("There"));
QPushButton* thing3 = new QPushButton(QObject::tr("Again"));
QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(thing1);
layout->addWidget(thing2);
layout->addWidget(thing3);
QWidget* widget = new QWidget();
widget->resize(300,300);
widget->setLayout(layout);
widget->show();
Output using a QFormLayout:
http://i.imgur.com/nWI28.png
Output using a QVBoxLayout:
http://i.imgur.com/lq0oX.png
I'd like the QVBoxLayout version to mimic the QFormLayout version.