I am developing a Qt application and changing the closing behavior using a closeEventvirtual function as follows:
class MainWindow(QMainWindow):
def closeEvent(self, event):
event.ignore()
self.hide()
self.trayicon.showMessage('Running', 'Running in the background.')
This works as expected. If I delete event.ignore(), the application will stop working, everything will be fine.
I also want to control the minimize event, so when the user clicks the minimize button in the title bar, I want to move the window, not minimize it. I cannot use the hideEventvirtual function because the event will still be sent to the window, so this code:
def hideEvent(self, event):
event.ignore()
self.move(0,0)
moves the window to the upper left and then minimizes it. event.ignore()not valid here, so I tried using QtCore.QObject.eventas follows:
def event(self, event):
if event.type() == QEvent.WindowStateChange:
if self.isMinimized():
event.ignore()
self.move(0,0)
return True
return False
, . ? ?