QFormLayout with QVBoxLayout
-
Hi everyone,
I want to make a FormLayout, where the label is a QLabel and the form right is QVBoxLayout. Unfortunately, the alignment doesn't work the way I want it.
QFormLayout* mLayout = new QFormLayout; QLabel* label1 = new QLabel(QStringLiteral("Name")); QLabel* label2 = new QLabel(QStringLiteral("Name")); QLabel* label3 = new QLabel(QStringLiteral("Name")); QVBoxLayout* vbox = new QVBoxLayout; vbox->addWidget(label2); vbox->addWidget(label3); mLayout->addRow(label1, vbox); this->setLayout(mLayout);
I would like to have the left label on the same height as the right upper label in the QVBoxLayout.
Turning on borders:
the label left is stretched for some reason and I can't figure out why.
Any help would be appreciated!
-
Hi everyone,
I want to make a FormLayout, where the label is a QLabel and the form right is QVBoxLayout. Unfortunately, the alignment doesn't work the way I want it.
QFormLayout* mLayout = new QFormLayout; QLabel* label1 = new QLabel(QStringLiteral("Name")); QLabel* label2 = new QLabel(QStringLiteral("Name")); QLabel* label3 = new QLabel(QStringLiteral("Name")); QVBoxLayout* vbox = new QVBoxLayout; vbox->addWidget(label2); vbox->addWidget(label3); mLayout->addRow(label1, vbox); this->setLayout(mLayout);
I would like to have the left label on the same height as the right upper label in the QVBoxLayout.
Turning on borders:
the label left is stretched for some reason and I can't figure out why.
Any help would be appreciated!
QFormLayout* mLayout = new QFormLayout;
QLabel* label1 = new QLabel(QStringLiteral("Name")); QLabel* label2 = new QLabel(QStringLiteral("Name")); QLabel* label3 = new QLabel(QStringLiteral("Name")); mLayout->addRow(label1, label2); mLayout->addRow(new QLabel(""), label3); this->setLayout(mLayout);
-
Hi,
thanks for the suggestion, unfortunately this is not what I want to achieve.
In your code, there is spacing between label2 and label3. But I want the spacing only between the actual rows. Of course I could work with trickst like an extra Spacing element etc. but that's kinda hacky again.Having a QFormLayout combinded with QVBoxLayout is exactly what I need and want (and makes the most sense). I would like to know why it's not working without the code from above, up to now it seems like a bug to me.
-
@leon_2001 said in QFormLayout with QVBoxLayout:
up to now it seems like a bug to me.
Why? The widget just fills out it's available height and therefore the left widget displays it's text centered. I would take a look at QLabel::alignment
-
@leon_2001 said in QFormLayout with QVBoxLayout:
up to now it seems like a bug to me.
Why? The widget just fills out it's available height and therefore the left widget displays it's text centered. I would take a look at QLabel::alignment
Which widget? The label on the left side doesn't seeem to fill out the complete avaiable height? Otherwise it would has the same height as the labels on the right together, wouldn't it?
Why has the left label exactly this height (which by the way stays the same, if you have more spacing in the VBox)