mouseMoveEvent在控件上无效
以下是我的代码
import sys
from PySide2.QtWidgets import QWidget, QApplication
from PySide2 import QtUiTools, QtCore
class mouseMoveEvent(QWidget):
def __init__(self):
super().__init__()
self.ui = UiLoader().loadUi('./ui/ui/test.ui', self)
self.ui.setMouseTracking(True)
self.show()
def mouseMoveEvent(self, e):
print('666')
class UiLoader(QtUiTools.QUiLoader):
_baseinstance = None
def createWidget(self, classname, parent=None, name=''):
if parent is None and self._baseinstance is not None:
widget = self._baseinstance
else:
widget = super(UiLoader, self).createWidget(classname, parent, name)
if self._baseinstance is not None:
setattr(self._baseinstance, name, widget)
return widget
def loadUi(self, uifile, baseinstance=None):
self._baseinstance = baseinstance
widget = self.load(uifile)
QtCore.QMetaObject.connectSlotsByName(widget)
return widget
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = mouseMoveEvent()
sys.exit(app.exec_())
其中窗口就只放了一个label
运行后,在界面其他地方是可以触发 mouseMoveEvent 的,在 label 上的时候就不触发,不知道有没有人遇见和我一样的情况,求帮助!非常感谢!