Making a layout visible?
-
I have added a QGridLayout to a window and have several other widgets positioned in it, so far so good.
I want to add another QGridLayout inside the first QGridLayout. When I add widgets to layout:
pobjGridLO->addWidget(pobjNode->pobjGetWidget(), intRow, intCol, 1, 1);
Where intRow and intCol are base 0 values. When I create the 2nd layout:
pobjGridLO->addWidget(pobjSubGridLO->widget(), itRow.i, itCol.i, 1, 1);
pobjGridLO is the first instance of QGridLayout, itRow.i and itCol.i are iterators through rows and columns of widgets to attached to the grid. pobjSubGridLO is a pointer to the 2nd layout that is created, here is the code that creates it:
pobjSubGridLO = new QGridLayout(pobjGridLO->widget()); if ( pobjSubGridLO != nullptr ) { pobjGridLO->addWidget(pobjSubGridLO->widget(), itRow.i, itCol.i, 1, 1);
I can see no evidence that the sub-layout has been added to the first layout, I've added widgets to the 2nd layout but I don't see these either.
Is there anything I can do to make the layout visible, e.g. give it a red background?
Can anyone tell me what I may have done wrong?
-
Hi,
Since you want to nest layouts, why don't you use the addLayout method ?
As for making them visible, no, layouts don't have "physical" appearance. But you can do that for the widgets within the layout.
-
Hi,
Since you want to nest layouts, why don't you use the addLayout method ?
As for making them visible, no, layouts don't have "physical" appearance. But you can do that for the widgets within the layout.
@SGaist thank you, since the widgets aren't visible I asked this question because I wanted some assurance that the layout is actually present where I've added it to be, I will try the addLayout now.
pobjGridLO->addLayout(pobjSubGridLO, itRow.i, itCol.i, Qt::AlignHCenter);
It works, thank you.