美文网首页
鼠标跟随

鼠标跟随

作者: 有之余 | 来源:发表于2019-11-05 18:08 被阅读0次
    from PyQt5.Qt import *
    import sys
    
    
    class Window(QWidget):
        def __init__(self):
            super().__init__()
            # 设置控件
            self.setWindowTitle('鼠标的相关操作')
            # 设置大小
            self.resize(500, 500)
            self.move(200, 200)
            self.setMouseTracking(True)
    
            # 更换鼠标的样式
            pixmap = QPixmap('xxx.png').scaled(50, 50)
            cursor = QCursor(pixmap)
            self.setCursor(cursor)
    
            lable = QLabel(self)
            # # 标签
            # self.label = lable
            lable.setText('blblblblblbl')
            lable.move(100, 100)
            lable.setStyleSheet("background-color:cyan;")
    
        def mouseMoveEvent(self, mv):
            print('鼠标移动', mv.localPos())
            lable = self.findChild(QLabel)  # 找到运动的鼠标位置
            lable.move(mv.localPos().x(), mv.localPos().y())
    
    
    app = QApplication(sys.argv)
    # 创建控件
    window = Window()
    # 展示控件
    window.show()
    # 退出
    sys.exit(app.exec_())
    
    

    相关文章

      网友评论

          本文标题:鼠标跟随

          本文链接:https://www.haomeiwen.com/subject/rveebctx.html