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. When clicking a button, how to make window transition to another window without opening a new window.
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Mobile and Embedded
linuxc++gui
7 Posts 2 Posters 6.0k 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.
  • M Offline
    M Offline
    marlenet15
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Looks like you want QStackedWidget or QStackedLayout

        M Offline
        M Offline
        marlenet15
        wrote on last edited by
        #3

        @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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0
          • M Offline
            M Offline
            marlenet15
            wrote on last edited by
            #5

            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
            0
            • M Offline
              M Offline
              marlenet15
              wrote on last edited by
              #6

              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
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                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
                1

                • Login

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