Dynamically creating GUIs on the same window
-
I am trying to dynamically instance new GUIs on to the current widget window. I tried doing this:
@QLabel* newLabel = new QLabel("Hello");
newLabel->show()@but that creates a new window with that widget.
Is it possible to dynamically create widgets on the same window?
-
You'll need to set the parent to the respective window. I.e. use the constructor that takes the label string as first and the parent QWidget as second argument.
-
Would I set the parent to the centralWidget in order for the widget to appear on the same window? That's the default object I believe.
-
Yes, for example.
-
Also, check out QLayout to control how you arrange your new widgets. Use centralWindow->setLayout() first, and then you can dynamically call addWidget() on the layout.
I'd start with "QVBoxLayout":http://qt-project.org/doc/qt-4.8/qvboxlayout.html or "QHBoxLayout":http://qt-project.org/doc/qt-4.8/qhboxlayout.html (vertical or horizontal boxes), and move on to more advanced layouts after that.