本文整理汇总了Python中PyQt5.Qt.QPropertyAnimation.state方法的典型用法代码示例。如果您正苦于以下问题:Python QPropertyAnimation.state方法的具体用法?Python QPropertyAnimation.state怎么用?Python QPropertyAnimation.state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QPropertyAnimation
的用法示例。
在下文中一共展示了QPropertyAnimation.state方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ThrobbingButton
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import state [as 别名]
class ThrobbingButton(QToolButton):
@pyqtProperty(int)
def icon_size(self):
return self._icon_size
@icon_size.setter
def icon_size(self, value):
self._icon_size = value
def __init__(self, *args):
QToolButton.__init__(self, *args)
# vertically size policy must be expanding for it to align inside a
# toolbar
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
self._icon_size = -1
QToolButton.setIcon(self, QIcon(I('donate.png')))
self.setText('\xa0')
self.animation = QPropertyAnimation(self, b'icon_size', self)
self.animation.setDuration(60/72.*1000)
self.animation.setLoopCount(4)
self.animation.valueChanged.connect(self.value_changed)
self.setCursor(Qt.PointingHandCursor)
self.animation.finished.connect(self.animation_finished)
def animation_finished(self):
self.icon_size = self.iconSize().width()
def enterEvent(self, ev):
self.start_animation()
def leaveEvent(self, ev):
self.stop_animation()
def value_changed(self, val):
self.update()
def start_animation(self):
if config['disable_animations']:
return
if self.animation.state() != self.animation.Stopped or not self.isVisible():
return
size = self.iconSize().width()
smaller = int(0.7 * size)
self.animation.setStartValue(smaller)
self.animation.setEndValue(size)
QMetaObject.invokeMethod(self.animation, 'start', Qt.QueuedConnection)
def stop_animation(self):
self.animation.stop()
self.animation_finished()
def paintEvent(self, ev):
size = self._icon_size if self._icon_size > 10 else self.iconSize().width()
p = QPainter(self)
opt = QStyleOptionToolButton()
self.initStyleOption(opt)
s = self.style()
opt.iconSize = QSize(size, size)
s.drawComplexControl(s.CC_ToolButton, opt, p, self)
示例2: ThrobbingButton
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import state [as 别名]
class ThrobbingButton(QToolButton):
def __init__(self, *args):
QToolButton.__init__(self, *args)
self.animation = QPropertyAnimation(self, 'iconSize', self)
self.animation.setDuration(60/72.*1000)
self.animation.setLoopCount(4)
self.normal_icon_size = QSize(64, 64)
self.animation.valueChanged.connect(self.value_changed)
self.setCursor(Qt.PointingHandCursor)
self.animation.finished.connect(self.animation_finished)
def set_normal_icon_size(self, w, h):
self.normal_icon_size = QSize(w, h)
self.setIconSize(self.normal_icon_size)
try:
self.setMinimumSize(self.sizeHint())
except:
self.setMinimumSize(QSize(w+5, h+5))
def animation_finished(self):
self.setIconSize(self.normal_icon_size)
def enterEvent(self, ev):
self.start_animation()
def leaveEvent(self, ev):
self.stop_animation()
def value_changed(self, val):
self.update()
def start_animation(self):
if config['disable_animations']:
return
if self.animation.state() != self.animation.Stopped or not self.isVisible():
return
size = self.normal_icon_size.width()
smaller = int(0.7 * size)
self.animation.setStartValue(QSize(smaller, smaller))
self.animation.setEndValue(self.normal_icon_size)
QMetaObject.invokeMethod(self.animation, 'start', Qt.QueuedConnection)
def stop_animation(self):
self.animation.stop()
self.animation_finished()
示例3: SlideFlip
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import state [as 别名]
class SlideFlip(QWidget):
# API {{{
# In addition the isVisible() and setVisible() methods must be present
def __init__(self, parent):
QWidget.__init__(self, parent)
self.setGeometry(0, 0, 1, 1)
self._current_width = 0
self.before_image = self.after_image = None
self.animation = QPropertyAnimation(self, 'current_width', self)
self.setVisible(False)
self.animation.valueChanged.connect(self.update)
self.animation.finished.connect(self.finished)
self.flip_forwards = True
self.setAttribute(Qt.WA_OpaquePaintEvent)
@property
def running(self):
'True iff animation is currently running'
return self.animation.state() == self.animation.Running
def initialize(self, image, forwards=True):
'''
Initialize the flipper, causes the flipper to show itself displaying
the full `image`.
:param image: The image to display as background
:param forwards: If True flipper will flip forwards, otherwise
backwards
'''
self.flip_forwards = forwards
self.before_image = QPixmap.fromImage(image)
self.after_image = None
self.setGeometry(0, 0, image.width(), image.height())
self.setVisible(True)
def __call__(self, image, duration=0.5):
'''
Start the animation. You must have called :meth:`initialize` first.
:param duration: Animation duration in seconds.
'''
if self.running:
return
self.after_image = QPixmap.fromImage(image)
if self.flip_forwards:
self.animation.setStartValue(image.width())
self.animation.setEndValue(0)
t = self.before_image
self.before_image = self.after_image
self.after_image = t
self.animation.setEasingCurve(QEasingCurve(QEasingCurve.InExpo))
else:
self.animation.setStartValue(0)
self.animation.setEndValue(image.width())
self.animation.setEasingCurve(QEasingCurve(QEasingCurve.OutExpo))
self.animation.setDuration(duration * 1000)
self.animation.start()
# }}}
def finished(self):
self.setVisible(False)
self.before_image = self.after_image = None
def paintEvent(self, ev):
if self.before_image is None:
return
canvas_size = self.rect()
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
p.drawPixmap(canvas_size, self.before_image,
self.before_image.rect())
if self.after_image is not None:
width = self._current_width
iw = self.after_image.width()
sh = min(self.after_image.height(), canvas_size.height())
if self.flip_forwards:
source = QRect(max(0, iw - width), 0, width, sh)
else:
source = QRect(0, 0, width, sh)
target = QRect(source)
target.moveLeft(0)
p.drawPixmap(target, self.after_image, source)
p.end()
def set_current_width(self, val):
self._current_width = val
#.........这里部分代码省略.........