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 do transition from 2nd page to 1st page
Qt 6.11 is out! See what's new in the release blog

How to do transition from 2nd page to 1st page

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.2k Views 1 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.
  • D Offline
    D Offline
    Dharmendra
    wrote on last edited by
    #1

    We have design Two Forms (MainWindow.ui & newwindow.ui) we are Sucessfully done designing of Transiting from 1st Form to 2nd form But we are not able to Transit from 2nd page to 1 st Page. below is the Program for Transition of 1st page to 2nd page. We are not able to do transition from 2nd page to 1st page

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>

    //added
    #include"newwindow.h"

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    //added
    public slots:
       void openNewWindow();
    
    //added name of the new window is NewWindow
    private:
       NewWindow *mMyNewWindow;
    
    private:
        Ui::MainWindow *ui;
    
    private slots:
        void on_mMyButton_clicked();
    

    };
    #endif // MAINWINDOW_H

    My newwindow.h is as follows.

    #ifndef NEWWINDOW_H
    #define NEWWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class NewWindow;
    }

    class NewWindow : public QMainWindow
    {
    Q_OBJECT

    public:
        explicit NewWindow(QWidget *parent = 0);
        ~NewWindow();
    
    private:
        Ui::NewWindow *ui;
    

    };

    #endif // NEWWINDOW_H

    My mainwindow.cpp is as follows.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    //Added
    connect(ui->mMyButton, SIGNAL(click()), this, SLOT(openNewWindow()));
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    My newwindow.cpp,

    #include "newwindow.h"
    #include "ui_newwindow.h"

    NewWindow::NewWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::NewWindow)
    {
    ui->setupUi(this);
    }

    NewWindow::~NewWindow()
    {
    delete ui;
    }

    My main.cpp as,

    #include <QtGui/QApplication>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec&#40;&#41;;
    

    }

    Thanks for all the information. And enjoy the programming with Qt.

    //In my mainwindow.cpp also add the following lines.

    void MainWindow::openNewWindow()
    {
    mMyNewWindow = new NewWindow();

    mMyNewWindow->show();
    

    }

    void MainWindow::on_mMyButton_clicked()
    {
    openNewWindow()

    }

    Dharmendra

    1 Reply Last reply
    0
    • B Offline
      B Offline
      b1gsnak3
      wrote on last edited by
      #2

      Easiest way to do what you need is to create one main window change it's layout using a stacked layout and voila :) and u can switch between how many pages you want...

      1 Reply Last reply
      0
      • B Offline
        B Offline
        butterface
        wrote on last edited by
        #3

        StackLayout sounds also good to me, but please use code tags for your snippets (put it between at signs).

        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