当前位置:网站首页>Pyqt5 out of focus monitoring no operation timer

Pyqt5 out of focus monitoring no operation timer

2022-07-07 04:09:00 AI vision netqi

pyqt5 Defocus No operation monitoring  

The following is from :

How to capture PyQt5 QMainWindow Lose focus -python Black hole network

timer Can be updated ui. 

class MainUi(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        self.init_ui()
        self.setFocus()
        QtWidgets.qApp.focusChanged.connect(self.on_focusChanged)

    @QtCore.pyqtSlot("QWidget*", "QWidget*")
    def on_focusChanged(self, old, now):
        if now == None:
            print(f"\nwindow lost focus: {self.isActiveWindow()}",time.strftime('%Y-%m-%d %H:%M:%S'))
            # self.setWindowState(QtCore.Qt.WindowMinimized)
            self.loss_start = time.time()  #  Record the start time 
            self.timer.start(1000*5)  #  Set the timer interval and start ,1 second 

    def lose_focus(self):
        if not self.isActiveWindow():
           
原网站

版权声明
本文为[AI vision netqi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207062135365066.html