[PyQT] After MessageBox app quits...why?

Demosthenes Koptsis demosthenesk at gmail.com
Mon Nov 7 05:10:31 EST 2016


i answered my own question.....


On 11/07/2016 11:44 AM, Demosthenes Koptsis wrote:
> because there is no window open and quits by default.
>
> You have to do two things:
>
> 1) Make sure that your SystemTray class has parent a QWidget
>
>     w = QtGui.QWidget()
>     trayIcon = SystemTrayIcon(QtGui.QIcon("virtualdvd.png"), w)
>
> 2) set quit to false
>
>     app.setQuitOnLastWindowClosed(False)
>
> ----------------------------
>
> Example
>
> ----------------------------
>
> def main():
>     app = QtGui.QApplication(sys.argv)
>     app.setQuitOnLastWindowClosed(False)
>
>     w = QtGui.QWidget()
>     trayIcon = SystemTrayIcon(QtGui.QIcon("virtualdvd.png"), w)
>
>     trayIcon.show()
>     sys.exit(app.exec_())
>
> if __name__ == '__main__':
>     main()
>
> On 11/07/2016 10:49 AM, Anssi Saari wrote:
>> Demosthenes Koptsis <demosthenesk at gmail.com> writes:
>>
>>> Hello, i have a PyQT systray app with a menu and two actions.
>>>
>>> Action1 is Exit and action2 display a MessageBox with Hello World 
>>> message.
>>>
>>> When i click OK to MessageBox app quits...why?
>>>
>>> http://pastebin.com/bVA49k1C
>> I haven't done anything with Qt in a while but apparently you need to
>> call QtGui.QApplication.setQuitOnLastWindowClosed(False) before
>> trayIcon.show().
>




More information about the Python-list mailing list