我有一堆QFormLayout和一堆QLineEdits。我还有一个QPushButton,我想放在对话框的水平中心。这是代码
//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
答案 0 :(得分:0)
在最后一条评论后添加了此代码:
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(layout);
mainLayout->addWidget(okay, 0, Qt::AlignCenter);
this->setLayout(mainLayout);
它有效!