开发者

How to do ignore quit() **and hide()** main window in closeEvent() in PyQt?

I want to do ignore quit and hide main window in closeEvent(), but closeEvent couldn't ignore program exit() while press Command-Q.

Test environment: MacOS, latest PyQt and Qt.

My code snippet a:

# ...

app = QtGui.QApplication(sys.argv)

# Why it doesn't works ?
# For more detail http://doc.qt.io/qt-5/qgu开发者_如何转开发iapplication.html#quitOnLastWindowClosed-prop
app.setQuitOnLastWindowClosed(False)

# ...

snippet b:

# ...

def closeEvent(self, event):
    if self._settings["close_confirm"]:
        btn_val, new_settings = ExitTipsDialog.get_input(settings=self._settings, parent=self)

        if btn_val == QtGui.QDialog.Accepted:
            if new_settings["close_main_pannel_action"] == MINIMIZE_WHILE_CLOSE_MAIN_PANNEL:

                # Oops, QApplication::lastWindowClosed() signal is emitted
                self.hide()

                event.ignore()
                return
        else:
            event.ignore()
            return
    else:
        if self._settings["close_main_pannel_action"] == MINIMIZE_WHILE_CLOSE_MAIN_PANNEL:
            event.ignore()
            self.hide()
            return

# ...

http://doc.qt.io/qt-5/qwidget.html#close said:

The QApplication::lastWindowClosed() signal is emitted when the last visible primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed. By default this attribute is set for all widgets except transient windows such as splash screens, tool windows, and popup menus.

How to do ignore quit() and hide() main window in closeEvent() ?


I'm not sure why you want to handle the hide event in closeEvent. There's hideEvent for that.

If this is not what you mean, perhaps you should clarify your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜