Create custom widget
-
Is this what you're looking for? if it is:
- put 2 labels above each other and select them both
- Ctrl+L (while the two labels are selected)
- Add a new label on the left and a button on the right
- select them all (all labels and button)
- Ctrl+H (while everything is selected)
- set the sizePolicy to preffered for everything
- resize the horizontal layout by selecting everything and use the corners to resize.
Edit: I am so sorry, but I didn't see that it was about a widget instead of layout.
- Add a QWidget item
- Select the entire layout as created by the steps above
- Drag the layout into the QWidget
- Add spacers if needed
- Set the size policy and resize if needed.
-
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)