问题
I have a main window which creates two widgets: the "main window" with menus and the main application and a widget that makes available various settings in its own window, disconnected from the main application.
Is there an event in Qt such that I can force the settings widget to close if i close/hide/X out the main application's window?
回答1:
You can:
1- make the settings widget a child of the main window
2- use an event filter to detect the close event of the main window (see QObject::installEventFilter()
and QCloseEvent
)
3- Override closeEvent
int the main window
回答2:
The main window has a closeEvent function you can override to close the other window:
void MainWindow::closeEvent(QCloseEvent *event)
{
otherWindow->close();
QMainWindow::closeEvent(event);
}
来源:https://stackoverflow.com/questions/24781409/qt-c-closing-two-widgets-when-one-is-closed