是否可以将小部件(按钮、标签等)动态添加到 Qt Designer 生成的中央小部件布局中?怎么做到呢?
谢谢!
当然,这很容易。您可以查看调试/发布目录中的 ui_mainwindow.h。我更喜欢在 QtDesigner 中为小部件设置布局而不是代码。是这样的:
//set layout programatically
auto layout = new QHBoxLayout(ui->centralWidget());
//or if you have set horizontalLayout in Qt Designer
auto layout = dynamic_cast<QHBoxLayout*>(ui->centralWidget->layout());
layout->addWidget(new QLabel("hello"));