0

When my app is running, if the user logs off I would like to pop up a window displaying some info and confirming the logout

class MyApp(QtWidgets.QApplication):

    def __init__(self, *args, **kwargs):
        super(MyApp, self).__init__(*args, **kwargs)
        self.commitDataRequest.connect(lambda manager: self.commitData(manager))

    @QtCore.pyqtSlot(QtGui.QSessionManager)
    def commitData(self, manager):
        print 'shutdown'

if __name__ == '__main__':
    qapplication = MyApp(sys.argv)
    QtWidgets.QApplication.setQuitOnLastWindowClosed(False) #interaction through tray icon
    application.exec_()

The issue is that it's not going into that slot method.

My app does not have a main window, its interfaces through the tray icon.

mingxiao
  • 1,712
  • 4
  • 21
  • 33
  • 1
    Can you provide a minimalistic working example that demonstrates the problem? – three_pineapples Sep 11 '14 at 02:02
  • "it's not going into that slot" can have many different causes. Your code is not enough to recreate the problem because self.commitDataRequest is not defined amongst others. – NoDataDumpNoContribution Sep 12 '14 at 11:02
  • according to http://qt-project.org/doc/qt-4.8/session.html#protocols-and-support-on-different-platforms , overriding that method should be all I need to do. Anyway looks like this bug is already documented https://bugreports.qt-project.org/browse/QTBUG-33034 – mingxiao Sep 12 '14 at 20:59

2 Answers2

0

You need to over ride your QtWidget:

    def closeEvent(self, event):

    quit_msg = "Are you sure you want to exit the program?"
    reply = QtGui.QMessageBox.question(self, 'Message', 
                  quit_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)

if reply == QtGui.QMessageBox.Yes:
    event.accept()
else:
    event.ignore()
XzibitGG
  • 330
  • 5
  • 18
-1

It looks like same as Prompt on exit in PyQt application.

Like you can ask to user if he/she really want to exit or not. Instead you'll show some information and then ask the question.

The answer:

https://stackoverflow.com/a/1414906/2681662

Community
  • 1
  • 1
MSH
  • 1,743
  • 2
  • 14
  • 22
  • not the same use case. My app does not have a main window, its interface is through the tray icon. And I don't want to prompt the user every time a window closes. – mingxiao Sep 10 '14 at 21:54