如何将QPushButton放置在对话框的水平中心



我有一个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

在最后一条注释后添加了以下代码:

QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(layout);
mainLayout->addWidget(okay, 0, Qt::AlignCenter);
this->setLayout(mainLayout);

它奏效了!

相关内容

  • 没有找到相关文章

最新更新