[pyqt5]pyqt5窗口被激活事件

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QEvent, Qt
from PyQt5.QtWidgets import QApplication


class Ui_MainWindow(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self)
        self.setupUi()

    def setupUi(self):
        self.setObjectName("MainWindow")
        self.setFixedSize(591, 299)
        self.centralwidget = QtWidgets.QWidget(self)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(20, 25, 61, 21))
        font = QtGui.QFont()
        font.setFamily("Agency FB")
        font.setPointSize(10)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.installEventFilter(self)

    def eventFilter(self, obj, event):
        #print(event.type())
        # If the AppWindow widget is shown on screen.
        if event.type() == QEvent.WindowActivate:
            print("The AppWindow activate")
            # Return true to inform that this event was consumed.
            return True
        # Return the object and event.
        return super(Ui_MainWindow, self).eventFilter(obj, event)

你可能感兴趣的:(pyqt5,qt,python,开发语言)