delete layout();
QGridLayout *gridLayout = new QGridLayout(this);
int cont = 0;
for (Category c : categories) {
cont++;
QVBoxLayout *verticalLayout;
verticalLayout = new QVBoxLayout();
gridLayout->setSpacing(cont);
gridLayout->addLayout(verticalLayout, 0, cont - 1);
QLabel *l;
l = new QLabel();
l->setText(c.getName());
l->setAlignment(Qt::AlignCenter);
verticalLayout->addWidget(l);
}
在mainWindow
中,我想在gridLayout
verticalLayout
周期时添加一个带有标签的for
和categories
答案 0 :(得分:0)
您没有将布局设置为任何小部件。您必须为要应用它的小部件调用函数 setLayout(gridLayout) 。希望它有所帮助