How to open a new window from the main window in Qt?

后端 未结 3 787
别跟我提以往
别跟我提以往 2021-01-12 14:35

I\'m new to qt programming and would like to know how to open a new window from the main window with the mainwindow disappearing? Is there any source code I can have a look

相关标签:
3条回答
  • 2021-01-12 15:15

    From a slot in your MainWindow call this code :

    QWidget *wdg = new QWidget;
    wdg->show();
    hide();//this will disappear main window
    
    0 讨论(0)
  • 2021-01-12 15:23

    try this instead

    this-> hide();
    
    0 讨论(0)
  • 2021-01-12 15:31

    In mainwindow.h

    Declare nw object of class NewWindow as below

    NewWindow *nw = new NewWindow();
    

    (Lets say we will open NewWindow, once the button1 is clicked on MainWindow)

    Then in on_pushButton_1_clicked() slot of class MainWindow:

    void MainWindow::on_pushButton_1_clicked(){ 
        nw->show();
        this->hide();
    }
    
    0 讨论(0)
提交回复
热议问题