Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to restore widget parent
Qt 6.11 is out! See what's new in the release blog

How to restore widget parent

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 5 Posters 1.4k Views
  • 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.
  • C ChrisW67

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

    CesarC Offline
    CesarC Offline
    Cesar
    wrote on last edited by
    #3

    @ChrisW67 but the red button is inside of the widget not the grid.

    JonBJ 1 Reply Last reply
    0
    • CesarC Cesar

      @ChrisW67 but the red button is inside of the widget not the grid.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #4

      @Cesar
      ? Your original screenshot is really unhelpful, you have left 3 push buttons named pushButton... and not told us which button is which.... If your red button is pushButton_3 then it is on a widget named widget. The icon indicates that you have set a QGridLayout (via Set Layout) in Designer on widget. Note that we are not talking about grid_Layout2 for this. So if you want to add it back it needs to be placed into that layout on widget.

      CesarC 1 Reply Last reply
      0
      • JonBJ JonB

        @Cesar
        ? Your original screenshot is really unhelpful, you have left 3 push buttons named pushButton... and not told us which button is which.... If your red button is pushButton_3 then it is on a widget named widget. The icon indicates that you have set a QGridLayout (via Set Layout) in Designer on widget. Note that we are not talking about grid_Layout2 for this. So if you want to add it back it needs to be placed into that layout on widget.

        CesarC Offline
        CesarC Offline
        Cesar
        wrote on last edited by
        #5

        @JonB in the picture you can see that the red button is promoted to 'AnimatedButton' so it's the pushButton, he is under a QWidget widget with is also set to Grid Layout.

        I tried setting it first to the gridLayout_2 and then setting the parent to widget but result in the same thin

        layout->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?

        Christian EhrlicherC JonBJ 2 Replies Last reply
        0
        • CesarC Cesar

          @JonB in the picture you can see that the red button is promoted to 'AnimatedButton' so it's the pushButton, he is under a QWidget widget with is also set to Grid Layout.

          I tried setting it first to the gridLayout_2 and then setting the parent to widget but result in the same thin

          layout->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?

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #6

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

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • CesarC Cesar

            @JonB in the picture you can see that the red button is promoted to 'AnimatedButton' so it's the pushButton, he is under a QWidget widget with is also set to Grid Layout.

            I tried setting it first to the gridLayout_2 and then setting the parent to widget but result in the same thin

            layout->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?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #7

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

            CesarC 1 Reply Last reply
            0
            • JonBJ JonB

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

              CesarC Offline
              CesarC Offline
              Cesar
              wrote on last edited by
              #8

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

              Y 1 Reply Last reply
              0
              • CesarC Cesar

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

                Y Offline
                Y Offline
                Ylvy
                wrote on last edited by
                #9

                @Cesar you could try widgetParent = parentWidget(); before setitng it parent to the centralWidget.

                CesarC 1 Reply Last reply
                0
                • Y Ylvy

                  @Cesar you could try widgetParent = parentWidget(); before setitng it parent to the centralWidget.

                  CesarC Offline
                  CesarC Offline
                  Cesar
                  wrote on last edited by Cesar
                  #10

                  @Ylvy same thing :(
                  the widget isn't 'attached' back to her parent

                  JonBJ 1 Reply Last reply
                  0
                  • CesarC Cesar

                    @Ylvy same thing :(
                    the widget isn't 'attached' back to her parent

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #11

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

                    Y 1 Reply Last reply
                    0
                    • JonBJ JonB

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

                      Y Offline
                      Y Offline
                      Ylvy
                      wrote on last edited by
                      #12
                      This post is deleted!
                      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