Solved Parent-Child Relationship
-
@SGaist
Example, here is how UI is designedState 1
|-------------------| | W1 | |-------------------| | W2 | |-------------------| | Open | | W3 | | | |-------------------|
W1
&W2
are the other widgets
W3
has a open button which would bring up the child widgetW31
.After clicking on the
Open
buttonState 2
|-------------------| | W1 | |-------------------| | W2 | |-------------------| | X | | W31 | | | |-------------------|
W31
has some details to be shown to the user. On pressingX
button button, UI would go back to State 1.In this scenario, When
Open
button is clicked, I want to hideW3
and showW31
.As I have mentioned above, when I call W3 hide, W31 's show crashes the application.
-
Wouldn't it make more sense to use a QStackedWidget ?
-
@SGaist Not thought about it. But, this is more like a pop-up widget comes up when clicking on 'open' and gets closed when we close it.
-
Ok, so since it's a popup, why hide the other widget ?
-
@SGaist That's a good point Sam. Actually, I don't need to hide the parent, when the child is being shown.
It was an attempt to understand if I can hide the parent when the child is being shown.Looks like we can't hide the parent when the child is being shown. I was trying to understand the reason and how Qt handles it.
-
@kumararajas said in Parent-Child Relationship:
Looks like we can't hide the parent when the child is being shown
You should be able to, when you hide the parent, after the child is actually shown
-
void ParentWidget::buttonClicked() { // create child UI childUI = new ChildWidget(this); this->hide(); childUI->show(); }
In the code snippet that I have mentioned above,
Afterthis->hide
which hides the parent,child->show
does not bring up the child UI. When I print the visibility state, it returnsfalse
-
@kumararajas said in Parent-Child Relationship:
In the code snippet that I have mentioned above,
After this->hide which hides the parent, child->show does not bring up the child UI. When I print the visibility state, it returns falseI said, show it first, then hide it
void ParentWidget::buttonClicked() { // create child UI childUI = new ChildWidget(this); childUI->show(); this->hide(); }
actually now that I read that, IIRC then the parent propagates the hide event to all it's (widget) children 🤔
So it shouldn't work
void ParentWidget::buttonClicked() { // create child UI childUI = new ChildWidget(this); childUI-> setWindowModality(Qt::ApplicationModal); childUI->show(); this->hide(); }
could work,
however, I haven't yet tested it -
@J-Hilk said in Parent-Child Relationship:
childUI-> setWindowModality(Qt::ApplicationModal);
I shall test and keep you posted with the results. Thank you.
-