How to use "try destroy window" event?
-
I have descendent by QMainWindow, QTabWidget with editors CodeEditor : public QPlainTextEdit.
Editor can be closed by many way : click X on tab, Ctrl+F4, menu File->Close and even exit program witgh Alt+F4.
I want not enable closing not saved editors until user not choose (Yes,No, Cancel).
How do it? -
Hi
You are in luck. That use case is the example from the docs :)
https://doc.qt.io/qt-5/qwidget.html#closeEventSo you override this function and its called when user tried to close app and then you can
reject it or allow it as you wish. -
But how to do with closeEvent not in MainWindow but CodeEditor which is tabWidget widget?
void CodeEditor::closeEvent(QCloseEvent *event) { if (document()->isModified()){ event->ignore(); } else { event->accept(); } }
when I debug, it call ignore when modified but anyway widget is closed
-
I have method
void TabWindow::closeTab(int index)
where "TabWindow" is my main window. I simply change this method. This method cover closing by tab,by menu and by shortcuts. Only closing whole app is not covered by this method, but closing app event you give me above, thanks!