I have the following code that gives me Lineedits (see picture):
QHBoxLayout *mainQHBoxLayout = new QHBoxLayout();
QWidget *trayQWidget = new QWidget();
trayQWidget->setLayout(mainQHBoxLayout);
ui.centralWidget->layout()->addWidget(trayQWidget);
for (int lauf = 10;lauf < 15;lauf++)
{
QTextEdit *edit = new QTextEdit;
edit->setText(QString("edit %1").arg(lauf));
edit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
edit->setMaximumWidth(8 * lauf);
edit->setMaximumHeight(7 * lauf);
edit->setEnabled(false);
edit->setAlignment(Qt::AlignCenter);
edit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
edit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mainQHBoxLayout->addWidget(edit);
mainQHBoxLayout->setAlignment(mainQHBoxLayout,Qt::AlignBottom);
}
mainQHBoxLayout->setSpacing(2);
mainQHBoxLayout->addStretch();
I am wondering why the Lineedits are not aligned to the bottom?
To achive the alignment i tried to add aditional QVBoxLayouts. Now the Allignemt ist OK but the spacing between the QlineEdits ist too big. (See picture)
QHBoxLayout *mainQHBoxLayout = new QHBoxLayout();
QWidget *trayQWidget = new QWidget();
trayQWidget->setLayout(mainQHBoxLayout);
ui.centralWidget->layout()->addWidget(trayQWidget);
for (int lauf = 10;lauf < 15;lauf++)
{
QVBoxLayout *myQVBoxLayout = new QVBoxLayout();
QWidget *itemQWidget = new QWidget();
itemQWidget->setLayout(myQVBoxLayout);
myQVBoxLayout->addStretch();
QTextEdit *edit = new QTextEdit;
edit->setText(QString("edit %1").arg(lauf));
edit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
edit->setMaximumWidth(8 * lauf);
edit->setMaximumHeight(7 * lauf);
edit->setEnabled(false);
edit->setAlignment(Qt::AlignCenter);
edit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
edit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
myQVBoxLayout->addWidget(edit);
mainQHBoxLayout->addWidget(itemQWidget);
}
mainQHBoxLayout->setSpacing(2);
mainQHBoxLayout->addStretch();
Has anybody an suggestion what could be my fault or what i could try next?
Framework is QT 5.6.1 Platform Windows10
I think the solution ist to set the Margin of the myQVBoxLayout to "0"