euraad
euraad

Reputation: 2856

How to set a new window into a GroupBox in QT?

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?

Upvotes: 1

Views: 189

Answers (1)

p-a-o-l-o
p-a-o-l-o

Reputation: 10067

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.

Upvotes: 1

Related Questions