PyQt-QtGui-QCursor

文章目录

  • 一、鼠标
    • 1.自定义鼠标

一、鼠标

PyQt-QtGui-QCursor_第1张图片

1.自定义鼠标

from PyQt5.QtWidgets import QApplication, QWidget,QLabel,QPushButton
import sys
from PyQt5.QtGui import QCursor
from PyQt5.QtGui import  QPixmap

class win(QWidget): #创建一个类,为了集成控件
    def __init__(self):
        super(win, self).__init__()
        self.setWindowTitle('窗口标题')
        self.resize(400,300)
        self.setup_ui()#控件布局函数

    def setup_ui(self):  #控件布局
        label = QLabel('标签控件', self)
        button = QPushButton('按钮', self)
        label.move(50, 50)
        label.setStyleSheet('background-color: green')
        button.move(300, 10)

        pixmap=QPixmap('./images/photo.png')   #创建一张像素图纸
        pixmap_scaled=pixmap.scaled(10,10)   #缩放pm图纸,赋值给图纸pm1 参数 图纸的宽高
        cursor=QCursor(pixmap_scaled,0,0)    #创建鼠标对象#参数1 图纸 参数2 参数3 鼠标热点坐标;默认-1,图纸中心点;0,0图纸左上角
        label.setCursor(cursor)  # 设置鼠标形状

if __name__=='__main__':
    app=QApplication(sys.argv)  #创建应用
    window=win()
    window.show()
    sys.exit(app.exec_())

你可能感兴趣的:(pyqt,python)