Platform: QT, Windows XP
I am new to Qt. I want to show another window(what to do to open it as dialog) from mainwindow
. I did "add New Item ->Qt Designer Form Class
", named it say MyWindow
. But how to show this MyWindow
from mainwindow
?
Patrice Bernassola
- Implement a slot in your QMainWindow where you will open your new Window,
- Place a widget on your QMainWindow,
- Connect a signal from this widget to a slot from the QMainWindow (for example: if the widget is a QPushButton connect the signal
click()
to the QMainWindow custom slot you have created).
Code example:
MainWindow.h
// ...
include "newwindow.h"
// ...
public slots:
void openNewWindow();
// ...
private:
NewWindow *mMyNewWindow;
// ...
}
MainWindow.cpp
// ...
MainWindow::MainWindow()
{
// ...
connect(mMyButton, SIGNAL(click()), this, SLOT(openNewWindow()));
// ...
}
// ...
void MainWindow::openNewWindow()
{
mMyNewWindow = new NewWindow(); // Be sure to destroy your window somewhere
mMyNewWindow->show();
// ...
}
This is an example on how display a custom new window. There are a lot of ways to do this.
来源:https://stackoverflow.com/questions/1518317/how-to-show-another-window-from-mainwindow-in-qt