Qt/C++ - Closing two widgets when one is closed

匆匆过客 提交于 2019-12-11 13:32:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!