In this post, @cgmb mentioned that :
The parent of a `QWidget` must be a `QWidget`. `QLayout` is not a `QWidget`.
Layouts exist to move and resize the children of a `QWidget`.
Though you may add child widgets by making calls on the layout, ultimately,
their parent will be the `QWidget` that the layout resides on.
For example, using findChild()
like this to find a QLayout
will return a nullptr
:
QVBoxLayout *keyLayout = inputFieldGroupBox->findChild<QVBoxLayout*>("keyBoxLayoutCea", Qt::FindChildrenRecursively);
As such, I've been forced to use itemAt()
to manually search for the layout:
QVBoxLayout *keyLayout = dynamic_cast<QVBoxLayout*>(firstHoriField->itemAt(3)->layout());
(firstHoriField
is a layout in which keyLayout
locates in, and inputFieldGroupBox
is a QGroupBox
which firstHoriField
locates in)
Is there any efficient/less prone to bug method which can be used to find a layout (knowing its name), because from the code above, it could be seen that the itemAt()
method is rather bruteforce-y, and if for some reason I change the indexes (for instance from 3
->2
), the program wouldn't run.