How to restore widget parent
-
@Cesar said in How to restore widget parent:
the code changes her default parent to the central widget so it can be resized above the other widgets.
By changing the red button's parent you are removing it from the layout. Resetting the red widget's parent does not put it back in the layout. Put it back in the grid layout.
-
@Cesar said in How to restore widget parent:
the code changes her default parent to the central widget so it can be resized above the other widgets.
By changing the red button's parent you are removing it from the layout. Resetting the red widget's parent does not put it back in the layout. Put it back in the grid layout.
-
@Cesar
? Your original screenshot is really unhelpful, you have left 3 push buttons namedpushButton...
and not told us which button is which.... If your red button ispushButton_3
then it is on a widget namedwidget
. The icon indicates that you have set aQGridLayout
(via Set Layout) in Designer onwidget
. Note that we are not talking aboutgrid_Layout2
for this. So if you want to add it back it needs to be placed into that layout onwidget
. -
@Cesar
? Your original screenshot is really unhelpful, you have left 3 push buttons namedpushButton...
and not told us which button is which.... If your red button ispushButton_3
then it is on a widget namedwidget
. The icon indicates that you have set aQGridLayout
(via Set Layout) in Designer onwidget
. Note that we are not talking aboutgrid_Layout2
for this. So if you want to add it back it needs to be placed into that layout onwidget
.@JonB in the picture you can see that the red button is promoted to 'AnimatedButton' so it's the
pushButton
, he is under aQWidget
widget
with is also set toGrid Layout
.I tried setting it first to the
gridLayout_2
and then setting the parent towidget
but result in the same thinlayout->addWidget(this, 0, 0, 1, 1); this->setParent(default_parent); this->show();
@JonB said in How to restore widget parent:
So if you want to add it back it needs to be placed into that layout on
widget
.could you give an example?
-
@JonB in the picture you can see that the red button is promoted to 'AnimatedButton' so it's the
pushButton
, he is under aQWidget
widget
with is also set toGrid Layout
.I tried setting it first to the
gridLayout_2
and then setting the parent towidget
but result in the same thinlayout->addWidget(this, 0, 0, 1, 1); this->setParent(default_parent); this->show();
@JonB said in How to restore widget parent:
So if you want to add it back it needs to be placed into that layout on
widget
.could you give an example?
@Cesar said in How to restore widget parent:
layout->addWidget(this, 0, 0, 1, 1);
this->show();This is just plain stupid - addWidget() adds the widget to the layout and sets the parent to the one where the layout is set to. Afterwards you directly set a new parent (and therefore remove it from the layout again) - what should this do?
-
@JonB in the picture you can see that the red button is promoted to 'AnimatedButton' so it's the
pushButton
, he is under aQWidget
widget
with is also set toGrid Layout
.I tried setting it first to the
gridLayout_2
and then setting the parent towidget
but result in the same thinlayout->addWidget(this, 0, 0, 1, 1); this->setParent(default_parent); this->show();
@JonB said in How to restore widget parent:
So if you want to add it back it needs to be placed into that layout on
widget
.could you give an example?
@Cesar said in How to restore widget parent:
So if you want to add it back it needs to be placed into that layout on widget.
could you give an example?
An example of adding a widget to a layout? You know how to do that:
layout->addWidget(...)
.
Accessing the layout on a widget?widget->layout()
. -
@Cesar said in How to restore widget parent:
So if you want to add it back it needs to be placed into that layout on widget.
could you give an example?
An example of adding a widget to a layout? You know how to do that:
layout->addWidget(...)
.
Accessing the layout on a widget?widget->layout()
.@Christian-Ehrlicher said in How to restore widget parent:
This is just plain stupid - addWidget() adds the widget to the layout and sets the parent to the one where the layout is set to. Afterwards you directly set a new parent (and therefore remove it from the layout again) - what should this do?
Well, it can be stupid to you that know how it works, but I'm having difficulty in understand how widgets/layout works.
@JonB I'm talking about an example of when hovering a widget setting he parent to the
central widget
and on exit hover set him back parent to whatever he was. -
@Christian-Ehrlicher said in How to restore widget parent:
This is just plain stupid - addWidget() adds the widget to the layout and sets the parent to the one where the layout is set to. Afterwards you directly set a new parent (and therefore remove it from the layout again) - what should this do?
Well, it can be stupid to you that know how it works, but I'm having difficulty in understand how widgets/layout works.
@JonB I'm talking about an example of when hovering a widget setting he parent to the
central widget
and on exit hover set him back parent to whatever he was. -
@Cesar you could try
widgetParent = parentWidget();
before setitng it parent to thecentralWidget
. -
@Cesar
So far as I understand, you are in the same position as you have been before. To get a widget back to exactly where it was, it is not enough to reset its parent. (Than on its own will probably place at the top left of the parent widget?) You also need to place it back wherever it was before on the parent's layout, isn't that the case for your situation? And you are not doing that. -
@Cesar
So far as I understand, you are in the same position as you have been before. To get a widget back to exactly where it was, it is not enough to reset its parent. (Than on its own will probably place at the top left of the parent widget?) You also need to place it back wherever it was before on the parent's layout, isn't that the case for your situation? And you are not doing that.