add C++ objects in Qt gui
-
Hello everyone,
I started using QT yesterday so feel free to be rude to me.I looked at some docs to get started but I couldn't find myself with it.
I created 2 frames in the Qt Creator Design Tab, but I want to add/edit some buttons to these Frames programmatically.
My goal is to create:
- 2 frames (already created using QWidgets) 1 of them is contained by a QscrollableArea so I can scroll between some Buttons that I added using widgets.
I'll attach a photo of my render, so my question is, how can I create a new Widget in the mainwindow.cpp? When I tried doing so he showed a "secondary" window in addition to the Design GUI I already had.
Thanks in advance!
-
C Christian Ehrlicher moved this topic from Qt Creator and other tools on
-
Hello everyone,
I started using QT yesterday so feel free to be rude to me.I looked at some docs to get started but I couldn't find myself with it.
I created 2 frames in the Qt Creator Design Tab, but I want to add/edit some buttons to these Frames programmatically.
My goal is to create:
- 2 frames (already created using QWidgets) 1 of them is contained by a QscrollableArea so I can scroll between some Buttons that I added using widgets.
I'll attach a photo of my render, so my question is, how can I create a new Widget in the mainwindow.cpp? When I tried doing so he showed a "secondary" window in addition to the Design GUI I already had.
Thanks in advance!
-
Hello everyone,
I started using QT yesterday so feel free to be rude to me.I looked at some docs to get started but I couldn't find myself with it.
I created 2 frames in the Qt Creator Design Tab, but I want to add/edit some buttons to these Frames programmatically.
My goal is to create:
- 2 frames (already created using QWidgets) 1 of them is contained by a QscrollableArea so I can scroll between some Buttons that I added using widgets.
I'll attach a photo of my render, so my question is, how can I create a new Widget in the mainwindow.cpp? When I tried doing so he showed a "secondary" window in addition to the Design GUI I already had.
Thanks in advance!
@Markeggi said in add C++ objects in Qt gui:
how can I create a new Widget in the mainwindow.cpp
Widgets should have a parent set upon creation (which would most likely be your main window in this case). Adding widgets to layouts also reparents them to the layout's widget. You should be using layouts for everything.
One way is to call
setCentralWidget()
on the main windows to set the widget which is the main part of the main windows. Otherwise set a plainQWidget
as the central widget, add a layout to it and then add your widget from the Qt Designer and your own widget to the layout.