Adding a custom widget into an existing layout.
-
Sooo, I got it. I think this is actually the proper way to do it, right? At least it's staying centered now. But the other qestions remain? Is this the way to do it?
static_cast<QGridLayout *>(ui->gridLayout)->addWidget(b, 0, 1, Qt::AlignCenter);
Thanks anyway for reading?
-
@m1212e said in Adding a custom widget into an existing layout.:
static_cast<QGridLayout *>(ui->gridLayout)
Why do you need a cast here?
-
@Christian-Ehrlicher
You're abolutely right :D
It's just an artifact from previous attempts.
Thanks! -
When you won't add your widget by code but directly in the designer you can take a look at promoting widgets.
-
Already did that, but thanks. Unfortunatly I want to add them in my code.
-
@m1212e
Hi
Just as a note. when i want to insert dynamically into a Designer created
ui, i often just add some test widgets and then go to the generated
code (in the setupUI function) and see how its inserted. This is especially useful for complex layouts. -
@m1212e said in Adding a custom widget into an existing layout.:
Is there any way to edit the auto generated code?
You should not as next time you build your project auto generated code will be overwritten :-)
-
@m1212e said in Adding a custom widget into an existing layout.:
That's a good idea, thanks. Is there any way to edit the auto generated code?
Hi
You must copy the code and make it your own.
But its very handy to visually build something and then get the code to create it dynamically.