在主窗口中看不到我的标签和布局

Can't see my label and layout in MainWindow

本文关键字:标签 布局 我的 看不到 窗口      更新时间:2023-10-16
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中,当在categories

中使用for循环时,我想添加一个带有标签的gridLayoutverticalLayout

您没有为任何小部件设置布局。您必须调用函数setLayout(gridLayout)您想要应用它的小部件。希望能有所帮助