https://img-blog.csdnimg.cn/7630017d3ee444eab9bdedf8d48d575f.png
from PyQt5.Qt import *
import sys
class MyQwidget(QWidget):
def __init__(self):
super().__init__()
def showEvent(self, a0) -> None:
print("窗口被展示出来",a0)
def closeEvent(self,a0) -> bool:
print("窗口被关闭了")
def moveEvent(self, a0) -> None:
print("窗口被移动了")
def resizeEvent(self, a0) -> None:
print("窗口改变了尺寸大小")
def enterEvent(self, a0) -> None:
print("鼠标进来了")
self.setStyleSheet("background-color: yellow;")
def leaveEvent(self, a0) -> None:
print("鼠标移出了控件范围了")
self.setStyleSheet("background-color: green;")
def mousePressEvent(self, a0) -> None:
print("鼠标被按下了")
def mouseReleaseEvent(self, a0) -> None:
print("鼠标被释放")
def mouseDoubleClickEvent(self, a0) -> None:
print("鼠标双击")
def mouseMoveEvent(self, a0) -> None:
print("鼠标移动了")
def keyPressEvent(self, a0) -> None:
print("键盘上某一个按键被按下了")
def keyReleaseEvent(self, a0) -> None:
print("键盘上某一个按键被释放了")
app = QApplication(sys.argv)
win = MyQwidget()
win.setWindowTitle("鼠标操作的相关案例")
win.move(200, 200)
win.show()
sys.exit(app.exec_())
使用方法