python PYQT5 键盘,鼠标,绘制,焦点,改变,输入法,事件的方法和使用例子

 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_())

 使用方法文章来源地址https://uudwc.com/A/AZebE

原文地址:https://blog.csdn.net/lizhenqi123456/article/details/131614037

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请联系站长进行投诉反馈,一经查实,立即删除!

h
上一篇 2023年07月13日 09:48
下一篇 2023年07月13日 09:49