参考下面动态追加控件的代码。CMyDialog::CMyDialog(QWidget *parent) : QWidget(parent){ Button *button = new Button("ABCD"); QGridLayout *mainLayout = new QGridLayout; mainLayout->addWidget(button, 0, 0, 1, 6); setLayout(mainLayout);}