Reputation: 1016
I have a QFormLayout with a bunch of QLineEdits. I also have a QPushButton that I want to place at the horizontal center of my dialog. This is the code
//ask for book name
le_book = new QLineEdit;
layout->addRow("Book: ", le_book);
//ask for author
le_author = new QLineEdit;
layout->addRow("Author: ", le_author);
//ask for uid
le_uid = new QLineEdit;
layout->addRow("UID: ", le_uid);
//ask for tags
fillComboBox();
//ask for quantity
sb_quantity = new QSpinBox;
layout->addRow("Quantity: ", sb_quantity);
okay = new QPushButton("Okay");
connect(okay, &QPushButton::clicked, this, &Dialog::onOkay);
//how to place this pushButton at the horizontal center
Upvotes: 0
Views: 1059
Reputation: 1016
Added this code after the last comment:
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(layout);
mainLayout->addWidget(okay, 0, Qt::AlignCenter);
this->setLayout(mainLayout);
And it worked!
Upvotes: 1