Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

python - PyQt5 event filter occassionally not gaining focus when window is deactivated

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

@TryHardLearner your code is very bad. Peoples no try code TryHardLearner..because as well as while true:.... and then my computer is crashed...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...