Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

window

qt

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 at?

like image 858
Learner Avatar asked Aug 01 '13 08:08

Learner


3 Answers

From a slot in your MainWindow call this code :

QWidget *wdg = new QWidget;
wdg->show();
hide();//this will disappear main window
like image 89
s4eed Avatar answered Sep 22 '22 13:09

s4eed


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();
}
like image 36
oya163 Avatar answered Sep 26 '22 13:09

oya163


try this instead

this-> hide();
like image 37
theChef613 Avatar answered Sep 23 '22 13:09

theChef613