F.Guerinoni F.Guerinoni - 1 month ago 7
C++ Question

Can't see my label and layout in MainWindow

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);
}


In
mainWindow
, I want to add one
gridLayout
and
verticalLayout
with a label when using
for
cycle in my
categories

Answer

You didn't set the layout to any widget. You have to call function setLayout(gridLayout) for the widget you want to apply it on. Hope it helps