Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    When clicking a button, how to make window transition to another window without opening a new window.

    Mobile and Embedded
    linux c++ gui
    2
    7
    4674
    Loading More Posts
    • 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.
    • M
      marlenet15 last edited by

      I know how to create a new window when clicking a button. However, I would like it so that when you click on a button ( for example, "Next" or "Ok") on a window, it transitions into the same window but with a different layout without creating a new window. I will be creating approximately 10 transitions which is why I don't want a lot of windows to be opening. I have been looking in a lot of forums but I can't seem to find anything. I am a beginner so I am not sure where to start.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        Looks like you want QStackedWidget or QStackedLayout

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

        M 1 Reply Last reply Reply Quote 0
        • M
          marlenet15 @SGaist last edited by

          @SGaist I was looking at their description and it states that it: "provides a stack of widgets where only one widget is visible at a time." However, I would like it so that multiple widgets are visible at a time. For example, window #1 will have like a sign in : text box, label, and a button. On window #2, it will have student input information. All the widgets will change once it has been transitioned into another window.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Take a look at the linked Config Dialog Example

            You'll see that one widget doesn't mean it can't be composed

            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 Reply Quote 0
            • M
              marlenet15 last edited by

              I am a beginner. Many of the things shown in the example I don't fully understand. Do you think you can show me a much simpler example if possible? I would really appreciate it.

              1 Reply Last reply Reply Quote 0
              • M
                marlenet15 last edited by

                Also, I just ran the program from the example you provided me link and it is not exactly what I am looking for. When I ran this program, it looks like it has three tabs and whenever you click on one of the tabs, it will go to a different window. I would like it so that when I click on the "Ok" button, it goes to the next window without opening a new one. I know it is too much of ask but I am lost.

                1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  This is a quick and dirty example from the top of my head. It could have been made simpler by using a lambda but so you'll see that QStackedWidget is working the way you want it.

                  class MyDialog : public QDialog
                  {
                  Q_OBJECT
                  
                  public:
                  explicit MyDialog(QWidget *parent=0);
                  
                  private slots:
                  void gotToPage2();
                  
                  private:
                  QStackedWidget *_stackedWidget;
                  };
                  
                  MyDialog::MyDialog(QWidget *parent)
                     : QDialog(parent)
                  {
                  
                  // Create first widget
                  QWidget *firstPage = new QWidget;
                  QLabel *instructionLabel = new QLabel(tr("Instruction for user"));
                  QLineEdit *userNameLineEdit = new QLineEdit;
                  QPushButton *page2PushButton = new QPushButton(tr("Page 2"));
                  QVBoxLayout *firstPageLayout = new QVBoxLayout(firstPage); // automatically set the layout on the widget
                  firstPageLayout->addWidget(instructionLabel);
                  firstPageLayout->addWidget(userNameLineEdit);
                  firstPageLayout->addWidget(page2PushButton);
                  
                  // Create second widget
                  QWidget *secondPage = new QWIdget;
                  QLineEdit *firstNameLineEdit = new QLineEdit;
                  QLineEdit *lastNameLineEdit = new QLineEdit;
                  QPushButton *endPushButton = new QPushButton(tr("End"));
                  QVBoxLayout *secondPageLayout = new QVBoxLayout(secondPage);
                  secondPageLayout->addWidget(firstName);
                  secondPageLayout->addWidget(lastNameLineEdit);
                  secondPageLayout->addWidget(endPushButton);
                  
                  _stackedWidget = new QStackedWidget;
                  stackedWidget->addWidget(firstPage);
                  stackedWidget->addWidget(secondPage);
                  
                  connect(page2PushButton, &QPushButton::clicked, this, &MyDialog::goToPage2);
                  }
                  
                  void MyDialog::gotToPage2()
                  {
                     stackedWidget->setCurrentIndex(1);
                  }
                  

                  Note that you could also be interested by QWizard

                  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 Reply Quote 1
                  • First post
                    Last post