如果我将鼠标移到标有“stop”文本的标签上,希望它能够改变变量“Stop”的值为True,以便能够暂停/停止我的程序。我查看了这段代码:Mouseover event filter for a PyQT Label,并尝试运行它,但没有任何显示。代码如下:
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5 import *
import sys
class mouseoverEvent(QtCore.QObject):
def __init__(self, parent):
super(mouseoverEvent, self).__init__(parent)
self.initUI()
def eventFilter(self, object, event):
if event.type() == QtCore.QEvent.MouseMove:
print( "mousemove!")
return True
else:
return False
def initUI(self):
self.filter = mouseoverEvent(self)
self.label.installEventFilter(self.filter)
self.lbl=QLabel(self)
self.lbl.setText(self,"hellojjj")
self.setGeometry(1000, 30, 300, 100)
self.setWindowTitle('QLineEdit')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = mouseoverEvent()
sys.exit(app.exec_())