Create custom widget
-
This post is deleted!
-
@t0msk said in Create custom widget:
Is possible to create this widget using Qt Designer and then assign values to it dynamically?
Yes. Just Create a new Widget with UI and .h and cpp file
You can then use this from (other) code to make as many instances of the Widget as you want.
say in a MainWindow and put them in a layout there. -
@mrjj said in Create custom widget:
@t0msk
Just as a note :)
If you really plan to use 100 instances of this, then maybe
you should use a layout inside a QScrollArea so it allows scrolling.
A layout alone. will not give scrollbarsThanks :) Would be great if I could create folders in Forms directory :)
-
@t0msk
Hi
Well you can.
Remove the ui/cpp/h from project. (dont check the delete file checkbox)
In the .pro file
you can add
FORMS += Controls/theForm.uiand you can put the ui file in the sub folder Controls
and then Add the UI to the project.You might also need to change the
INCLUDES +=Controls/theForm.h
and
SOURCES +=Controls/theForm.cppfor it to find the .cpp and .h
-
@t0msk said in Create custom widget:
ui->scrollAreaWidgetContents
Hi
Since you have ui. do the following.
Place any widget inside scroll area. (like button)
Right click besides this widget. (in scroll area)
Choose a layout in the layout menu.
Now delete this widget again. (the button)
The layout will stay!
Notice the name of the layout
then from code
ui->thenewlayoutname->addwidget(xx); -
@t0msk
Hi
Look in the layout section of the properties.
to see the name.And yes, its slightly confusing as the structure is a bit flatten
so
its not
ui->scrollareaSomething->layout
but just
ui->verticalLayout_5->addwidget(xxx)