I want to create a customizedwindow such that whenever window is deactivated.
The window becomes the 'active' window and regains the focus to the window
Below code is sort of working but randomly stops making the window 'active' after several window
deactivates, when this happens the app just blinks on the bottom of the toolbar or is just highlighted.
(Btw im using windows 7 if it matters)
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5 import QtCore
import sys
class myWindow(QMainWindow):
def __init__(self, parent=None):
super(myWindow, self).__init__(parent)
self.installEventFilter(self)
self.counter = 0
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.WindowDeactivate:
self.counter += 1
print(self.counter)
self.raise_()
self.activateWindow()
return False
return False
if __name__ == '__main__':
app = QApplication(sys.argv)
win = myWindow()
win.show()
sys.exit(app.exec())
question from:
https://stackoverflow.com/questions/65895126/pyqt5-event-filter-occassionally-not-gaining-focus-when-window-is-deactivated 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…