Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Parent-Child Relationship
Forum Updated to NodeBB v4.3 + New Features

Parent-Child Relationship

Scheduled Pinned Locked Moved Solved Mobile and Embedded
14 Posts 3 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J J.Hilk
    11 Dec 2019, 09:36

    @kumararajas
    I take a wilde guess here and say parent widget and child widget are the only visible widgets of your application ? And you did not quitOnLastWindowClosed to false ?

    https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop

    K Offline
    K Offline
    kumararajas
    wrote on 11 Dec 2019, 11:19 last edited by
    #3

    @J-Hilk There are many other widgets as well

    ParentWidget that i have mentioned is one widget of the application. There are other widgets too. I haven't used quitOnLastWindowClosed in my application.

    --Kumar

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 11 Dec 2019, 16:20 last edited by
      #4

      Hi,

      If your parent widget is the only one shown and you hide it before showing your child widget, then the application will stop because there's no more widgets to show therefore deletion will happen.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply 12 Dec 2019, 10:45
      1
      • S SGaist
        11 Dec 2019, 16:20

        Hi,

        If your parent widget is the only one shown and you hide it before showing your child widget, then the application will stop because there's no more widgets to show therefore deletion will happen.

        K Offline
        K Offline
        kumararajas
        wrote on 12 Dec 2019, 10:45 last edited by
        #5

        @SGaist
        Example, here is how UI is designed

        State 1

        |-------------------|
        |      W1           |
        |-------------------|
        |       W2          |
        |-------------------|
        |              Open |
        |       W3          |
        |                   |
        |-------------------|
        

        W1 & W2 are the other widgets
        W3 has a open button which would bring up the child widget W31.

        After clicking on the Open button

        State 2

        |-------------------|
        |      W1           |
        |-------------------|
        |       W2          |
        |-------------------|
        |                 X |
        |       W31         |
        |                   |
        |-------------------|
        

        W31 has some details to be shown to the user. On pressing X button button, UI would go back to State 1.

        In this scenario, When Open button is clicked, I want to hide W3 and show W31.

        As I have mentioned above, when I call W3 hide, W31 's show crashes the application.

        --Kumar

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Dec 2019, 23:26 last edited by
          #6

          Wouldn't it make more sense to use a QStackedWidget ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          K 1 Reply Last reply 13 Dec 2019, 06:49
          0
          • S SGaist
            12 Dec 2019, 23:26

            Wouldn't it make more sense to use a QStackedWidget ?

            K Offline
            K Offline
            kumararajas
            wrote on 13 Dec 2019, 06:49 last edited by
            #7

            @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.

            --Kumar

            K 1 Reply Last reply 17 Feb 2020, 05:30
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 13 Dec 2019, 22:22 last edited by
              #8

              Ok, so since it's a popup, why hide the other widget ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              K 1 Reply Last reply 16 Dec 2019, 12:13
              0
              • S SGaist
                13 Dec 2019, 22:22

                Ok, so since it's a popup, why hide the other widget ?

                K Offline
                K Offline
                kumararajas
                wrote on 16 Dec 2019, 12:13 last edited by
                #9

                @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.

                --Kumar

                J 1 Reply Last reply 16 Dec 2019, 12:23
                0
                • K kumararajas
                  16 Dec 2019, 12:13

                  @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.

                  J Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 16 Dec 2019, 12:23 last edited by
                  #10

                  @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


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  K 1 Reply Last reply 17 Dec 2019, 13:30
                  0
                  • J J.Hilk
                    16 Dec 2019, 12:23

                    @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

                    K Offline
                    K Offline
                    kumararajas
                    wrote on 17 Dec 2019, 13:30 last edited by
                    #11

                    @J-Hilk

                    void ParentWidget::buttonClicked()
                    {
                        // create child UI
                        childUI = new ChildWidget(this);
                    
                         this->hide();
                        childUI->show();
                    }
                    

                    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 false

                    --Kumar

                    J 1 Reply Last reply 17 Dec 2019, 13:32
                    0
                    • K kumararajas
                      17 Dec 2019, 13:30

                      @J-Hilk

                      void ParentWidget::buttonClicked()
                      {
                          // create child UI
                          childUI = new ChildWidget(this);
                      
                           this->hide();
                          childUI->show();
                      }
                      

                      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 false

                      J Offline
                      J Offline
                      J.Hilk
                      Moderators
                      wrote on 17 Dec 2019, 13:32 last edited by J.Hilk
                      #12

                      @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 false

                      I 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


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      K 1 Reply Last reply 26 Dec 2019, 08:04
                      1
                      • J J.Hilk
                        17 Dec 2019, 13:32

                        @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 false

                        I 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

                        K Offline
                        K Offline
                        kumararajas
                        wrote on 26 Dec 2019, 08:04 last edited by
                        #13

                        @J-Hilk said in Parent-Child Relationship:

                        childUI-> setWindowModality(Qt::ApplicationModal);

                        I shall test and keep you posted with the results. Thank you.

                        --Kumar

                        1 Reply Last reply
                        0
                        • K kumararajas
                          13 Dec 2019, 06:49

                          @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.

                          K Offline
                          K Offline
                          kumararajas
                          wrote on 17 Feb 2020, 05:30 last edited by
                          #14

                          @J-Hilk @SGaist I have moved on with Sam's approach on why to hide the parent widget when it is being a pop-up. It worked for me, I couldn't test the windowModality.

                          Thank you for the help.

                          --Kumara

                          --Kumar

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved