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. Runtime layout
Forum Updated to NodeBB v4.3 + New Features

Runtime layout

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 624 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.
  • canellasC Offline
    canellasC Offline
    canellas
    wrote on last edited by
    #1

    Hi!

    In my application there is a QFrame, say F, and inside it there are 3 other QFrame objects, say A, B and C. F's layout is vertical, with A at the top, followed by B and C.
    In A there are two QRadionButton objects, and depending on the user choice, B or C should be visible. That does not seem hard to do, but the layout in F is broken when the Window is displayed, and is only fixed when I click one of the QRadionButton in A, as this code is executed:

    {
      if (ui->rdbA->isChecked()) {
        ui->fraB->setVisible(false);
        ui->fraA->setVisible(true);
        ui->fraF->layout()->removeWidget(ui->fraB);
        ui->fraF->layout()->addWidget(ui->fraA);
      } else {
        ui->fraB->setVisible(true);
        ui->fraA->setVisible(false);
        ui->fraF->layout()->addWidget(ui->fraB);
        ui->fraF->layout()->removeWidget(ui->fraA);
      }
      this->setGeometry(parentWidget()->x(),
                        parentWidget()->y(),
                        parentWidget()->width(),
                        parentWidget()->height());
    }
    

    Could anyone, please, give me any idea, or reference, on how to do it?

    Thanks!

    JonBJ 1 Reply Last reply
    0
    • canellasC canellas

      Hi!

      In my application there is a QFrame, say F, and inside it there are 3 other QFrame objects, say A, B and C. F's layout is vertical, with A at the top, followed by B and C.
      In A there are two QRadionButton objects, and depending on the user choice, B or C should be visible. That does not seem hard to do, but the layout in F is broken when the Window is displayed, and is only fixed when I click one of the QRadionButton in A, as this code is executed:

      {
        if (ui->rdbA->isChecked()) {
          ui->fraB->setVisible(false);
          ui->fraA->setVisible(true);
          ui->fraF->layout()->removeWidget(ui->fraB);
          ui->fraF->layout()->addWidget(ui->fraA);
        } else {
          ui->fraB->setVisible(true);
          ui->fraA->setVisible(false);
          ui->fraF->layout()->addWidget(ui->fraB);
          ui->fraF->layout()->removeWidget(ui->fraA);
        }
        this->setGeometry(parentWidget()->x(),
                          parentWidget()->y(),
                          parentWidget()->width(),
                          parentWidget()->height());
      }
      

      Could anyone, please, give me any idea, or reference, on how to do it?

      Thanks!

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

      @canellas
      What do you mean by "but the layout in F is broken when the Window is displayed"?

      It will only correctly show one frame when the code you show gets executed, as that sets up to view one frame, correctly. (Or is your question about a specific bit of the code?) So that's reasonable, no?

      However, before you spend time on this, would using a QStackedWidget (https://doc.qt.io/qt-5/qstackedwidget.html), which is designed for swapping between multiple widgets so only one is shown at a time (either of your B or C), be better for what you're trying to do here?

      canellasC 2 Replies Last reply
      0
      • JonBJ JonB

        @canellas
        What do you mean by "but the layout in F is broken when the Window is displayed"?

        It will only correctly show one frame when the code you show gets executed, as that sets up to view one frame, correctly. (Or is your question about a specific bit of the code?) So that's reasonable, no?

        However, before you spend time on this, would using a QStackedWidget (https://doc.qt.io/qt-5/qstackedwidget.html), which is designed for swapping between multiple widgets so only one is shown at a time (either of your B or C), be better for what you're trying to do here?

        canellasC Offline
        canellasC Offline
        canellas
        wrote on last edited by canellas
        #3

        @JonB ,

        First of all, thanks for your time.

        I wrapped the code in a method, and called it in the constructor of the QMainWindow. I guess I should call in another moment, right? Maybe on some show event...

        I though of QStackWidget, but that would allow the controls (QWidget) in B and C to be used, so when the user clicked on the final OK, I would not know id I should consider the data in B or C. I mean, I would like to direct the user, making him/her to explicitly choose B or C data. (dummy edit)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Are you trying to implement some sort of wizard ? If so, then QWizard is your friend.

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

          1 Reply Last reply
          0
          • canellasC Offline
            canellasC Offline
            canellas
            wrote on last edited by
            #5

            @SGaist ,

            Not really. I just wanted to show a frame B or C, according to a QRadioButton, but the way I was trying to do, the layout was messed up. @JonB was right by telling to use QStackWidget. I did not know it well, and I though the user would be able to switch between pages.
            So, thank you all for your help!

            1 Reply Last reply
            0
            • JonBJ JonB

              @canellas
              What do you mean by "but the layout in F is broken when the Window is displayed"?

              It will only correctly show one frame when the code you show gets executed, as that sets up to view one frame, correctly. (Or is your question about a specific bit of the code?) So that's reasonable, no?

              However, before you spend time on this, would using a QStackedWidget (https://doc.qt.io/qt-5/qstackedwidget.html), which is designed for swapping between multiple widgets so only one is shown at a time (either of your B or C), be better for what you're trying to do here?

              canellasC Offline
              canellasC Offline
              canellas
              wrote on last edited by
              #6

              @JonB ,

              I marked my reply to you comment as the best, but I meant to mark your comment as the best. Do you know how to change it?

              JonBJ 1 Reply Last reply
              0
              • canellasC canellas

                @JonB ,

                I marked my reply to you comment as the best, but I meant to mark your comment as the best. Do you know how to change it?

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

                @canellas
                Very kind of you. Only Grand Wizards here know how to mark someone else's post as the solution, I have seen others do it in mysterious circumstances but have not graduated that far myself...

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  AFAIK, it's a know issue of the forum software. It might have been fixed since last time I saw the report but I haven't checked recently.

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

                  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