Hemil
Hemil

Reputation: 1016

How to place QPushButton at the horizontal center of the dialog

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

Answers (1)

Hemil
Hemil

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

Related Questions