Home > Blockchain >  How to set a new window into a GroupBox in QT?
How to set a new window into a GroupBox in QT?

Time:02-18

I have a Window with a Group Box called Function control box

enter image description here

I want to include this window into that group box

enter image description here

I do that by using this code

ui->functionControlBoxGroupBox->setParent(componentIdentification);

Where componentIdentification in an UI object of the window above.

But it seems that nothing happens. Why?

This is what happening. From this:

enter image description here

To this:

enter image description here

Question:

How can I import a complete window form into a group box in QT?

CodePudding user response:

Conceptually, the group box is supposed to be the other window's parent (not the opposite), thus you should do:

componentIdentification->setParent(ui->functionControlBoxGroupBox);

A better way to do the same thing: set a layout to the parent (the group box) and add the child window to the layout, i.e., in construction:

ui->functionControlBoxGroupBox->setLayout(new QGridLayout());

somewhere else, later:

ui->functionControlBoxGroupBox->layout()->addWidget(componentIdentification);

This way, the group box is automatically set as the component's parent.

  • Related