[SOLVED] Add widgets manually to Qt designer generated code
First: I stated using qt yesterday so be easy on me please.
I created a simple layout with designer and now I want to add new widgets to it manually, but as I see it looks impossible, since there is no “redraw” or such. Is there any way to do it, apart from copying the code from setupUi and discarding the gui design?
Here is what I’m doing:
- MapArea wtf;
- //and now something here to redraw the window with the new widgets
Since you have already created your QMainWindow in the designer you can write the following code in your constructor:
- MainWindow::MainWindow(QWidget *parent) :
- ui(new Ui::MainWindow)
- QHBoxLayout *top = new QHBoxLayout;
- QHBoxLayout *bottom = new QHBoxLayout;
- QHBoxLayout *btnLayout = new QHBoxLayout;
This is just an example to add widgets programatically. It shows user information with some buttons. You can start with the basics provided on internet and also Books [qt-project.org] on Qt.
Thanks, my bad… (cause I’ve just did the same thing you wrote). The actual problem was that I already set a layout for the ‘widget’ component and I tried to add a new one in the code above, thus nothing happened. Now with this, it works (compare to the original code snippet):