pyqt5 官方例子笔记 animate-1

animatedtiles.py
总结:这个小程序,主要涉及到控件的布局(boundingRect Method),形状的绘制(shape函数重载来自定义控件的形状),控件图片的加载(资源文件的引入pyrcc,Button对象将资源对象最为初始化参数),整个界面的大体布局(scene view graphicsitem 各种qt对象之间的依赖关系),动态绘图过程(QState状态机)

注释即是笔记,留作下次的备忘

from PyQt5.QtCore import (pyqtProperty, pyqtSignal, QEasingCurve, QObject,
        QParallelAnimationGroup, QPointF, QPropertyAnimation, qrand, QRectF,
        QState, QStateMachine, Qt, QTimer)
from PyQt5.QtGui import (QBrush, QLinearGradient, QPainter, QPainterPath,
        QPixmap)
from PyQt5.QtWidgets import (QApplication, QGraphicsItem, QGraphicsPixmapItem,
        QGraphicsRectItem, QGraphicsScene, QGraphicsView, QGraphicsWidget,
        QStyle)

import animatedtiles_rc


# PyQt doesn't support deriving from more than one wrapped class so we use
# composition and delegate the property.
class Pixmap(QObject):
    def __init__(self, pix):
        #父类初始化
        super(Pixmap, self).__init__()

        self.pixmap_item = QGraphicsPixmapItem(pix)
        self.pixmap_item.setCacheMode(QGraphicsItem.DeviceCoordinateCache)

    def _set_pos(self, pos):
        self.pixmap_item.setPos(pos)

    # 类似于C# 字段调用方法  python里面property函数
    pos = pyqtProperty(QPointF, fset=_set_pos)


class Button(QGraphicsWidget):
    pressed = pyqtSignal()

    def __init__(self, pixmap, parent_arg=None):
        #QGraphicsWidget :_init__ (self, QGraphicsItem parent = None, Qt.WindowFlags wFlags = 0)
        #The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene
        super(Button, self).__init__(parent_arg)

        self._pix = pixmap
        #设置悬停时间是否接受,系统一直跟随鼠标检测是否悬停在一个控件上
        self.setAcceptHoverEvents(True)
   
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值