python - QT : Disable keyboard shortcut for quitting mac application or identify allow only closebutton event to quit application -
in mac command + q keyboard shortcut quits of applications.
in case, want disable application have developed in qt.
or there way identify close event raised clicking close button of application window, if can identify it, not proceed quit rest of close event calls overriding close function in qt.
surely can find light go wanted anyone's help.
extend qtgui.qapplication::events() method receive (command + q) mac osx keyboard shortcut close event , ignore it.
below sample pyqt (code achieve it.
#! /usr/bin/python import sys import os pyqt4 import qtgui class notepad(qtgui.qmainwindow): def __init__(self): super(notepad, self).__init__() self.initui() def initui(self): self.setgeometry(300,300,300,300) self.setwindowtitle('notepad') self.show() self.raise_() #def keypressevent(self, keyevent): # print(keyevent,'hi') # print('close 0', keyevent.inputmethod) # if keyevent.key() != 16777249: # super().keypressevent(keyevent) # else: # print(dir(keyevent)) # return false def closeevent(self, event): reply = qtgui.qmessagebox.question(self, 'message', "are sure quit?", qtgui.qmessagebox.yes | qtgui.qmessagebox.no, qtgui.qmessagebox.no) if reply == qtgui.qmessagebox.yes: event.accept() else: event.ignore() def main(): app = application() notepad = notepad() sys.exit(app.exec_()) class application(qtgui.qapplication): def event(self, event): # ignore command + q close app keyboard shortcut event in mac if event.type() == qtcore.qevent.close , event.spontaneous(): if sys.platform.startswith('darwin'): event.ignore() return false thanks everyone
Comments
Post a Comment