本文整理汇总了Python中PyQt5.Qt.QPropertyAnimation.setKeyValueAt方法的典型用法代码示例。如果您正苦于以下问题:Python QPropertyAnimation.setKeyValueAt方法的具体用法?Python QPropertyAnimation.setKeyValueAt怎么用?Python QPropertyAnimation.setKeyValueAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QPropertyAnimation
的用法示例。
在下文中一共展示了QPropertyAnimation.setKeyValueAt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CoverDelegate
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setKeyValueAt [as 别名]
class CoverDelegate(QStyledItemDelegate):
MARGIN = 4
TOP, LEFT, RIGHT, BOTTOM = object(), object(), object(), object()
@pyqtProperty(float)
def animated_size(self):
return self._animated_size
@animated_size.setter
def animated_size(self, val):
self._animated_size = val
def __init__(self, parent):
super(CoverDelegate, self).__init__(parent)
self._animated_size = 1.0
self.animation = QPropertyAnimation(self, b'animated_size', self)
self.animation.setEasingCurve(QEasingCurve.OutInCirc)
self.animation.setDuration(500)
self.set_dimensions()
self.cover_cache = CoverCache()
self.render_queue = LifoQueue()
self.animating = None
self.highlight_color = QColor(Qt.white)
self.rating_font = QFont(rating_font())
def set_dimensions(self):
width = self.original_width = gprefs['cover_grid_width']
height = self.original_height = gprefs['cover_grid_height']
self.original_show_title = show_title = gprefs['cover_grid_show_title']
self.original_show_emblems = gprefs['show_emblems']
self.orginal_emblem_size = gprefs['emblem_size']
self.orginal_emblem_position = gprefs['emblem_position']
self.emblem_size = gprefs['emblem_size'] if self.original_show_emblems else 0
try:
self.gutter_position = getattr(self, self.orginal_emblem_position.upper())
except Exception:
self.gutter_position = self.TOP
if height < 0.1:
height = auto_height(self.parent())
else:
height *= self.parent().logicalDpiY() * CM_TO_INCH
if width < 0.1:
width = 0.75 * height
else:
width *= self.parent().logicalDpiX() * CM_TO_INCH
self.cover_size = QSize(width, height)
self.title_height = 0
if show_title:
f = self.parent().font()
sz = f.pixelSize()
if sz < 5:
sz = f.pointSize() * self.parent().logicalDpiY() / 72.0
self.title_height = max(25, sz + 10)
self.item_size = self.cover_size + QSize(2 * self.MARGIN, (2 * self.MARGIN) + self.title_height)
if self.emblem_size > 0:
extra = self.emblem_size + self.MARGIN
self.item_size += QSize(extra, 0) if self.gutter_position in (self.LEFT, self.RIGHT) else QSize(0, extra)
self.calculate_spacing()
self.animation.setStartValue(1.0)
self.animation.setKeyValueAt(0.5, 0.5)
self.animation.setEndValue(1.0)
def calculate_spacing(self):
spc = self.original_spacing = gprefs['cover_grid_spacing']
if spc < 0.01:
self.spacing = max(10, min(50, int(0.1 * self.original_width)))
else:
self.spacing = self.parent().logicalDpiX() * CM_TO_INCH * spc
def sizeHint(self, option, index):
return self.item_size
def render_field(self, db, book_id):
is_stars = False
try:
field = db.pref('field_under_covers_in_grid', 'title')
if field == 'size':
ans = human_readable(db.field_for(field, book_id, default_value=0))
else:
mi = db.get_proxy_metadata(book_id)
display_name, ans, val, fm = mi.format_field_extended(field)
if fm and fm['datatype'] == 'rating':
ans = rating_to_stars(val, fm['display'].get('allow_half_stars', False))
is_stars = True
return ('' if ans is None else unicode_type(ans)), is_stars
except Exception:
if DEBUG:
import traceback
traceback.print_exc()
return '', is_stars
def render_emblem(self, book_id, rule, rule_index, cache, mi, db, formatter, template_cache):
ans = cache[book_id].get(rule, False)
if ans is not False:
return ans, mi
ans = None
if mi is None:
#.........这里部分代码省略.........
示例2: Pointer
# 需要导入模块: from PyQt5.Qt import QPropertyAnimation [as 别名]
# 或者: from PyQt5.Qt.QPropertyAnimation import setKeyValueAt [as 别名]
class Pointer(QWidget):
def __init__(self, gui):
QWidget.__init__(self, gui)
self.setObjectName('jobs_pointer')
self.setVisible(False)
self.resize(100, 80)
self.animation = QPropertyAnimation(self, "geometry", self)
self.animation.setDuration(750)
self.animation.setLoopCount(2)
self.animation.setEasingCurve(QEasingCurve.Linear)
self.animation.finished.connect(self.hide)
taily, heady = 0, 55
self.arrow_path = QPainterPath(QPointF(40, taily))
self.arrow_path.lineTo(40, heady)
self.arrow_path.lineTo(20, heady)
self.arrow_path.lineTo(50, self.height())
self.arrow_path.lineTo(80, heady)
self.arrow_path.lineTo(60, heady)
self.arrow_path.lineTo(60, taily)
self.arrow_path.closeSubpath()
c = self.palette().color(QPalette.Active, QPalette.WindowText)
self.color = QColor(c)
self.color.setAlpha(100)
self.brush = QBrush(self.color, Qt.SolidPattern)
# from PyQt5.Qt import QTimer
# QTimer.singleShot(1000, self.start)
@property
def gui(self):
return self.parent()
def point_at(self, frac):
return (self.path.pointAtPercent(frac).toPoint() -
QPoint(self.rect().center().x(), self.height()))
def rect_at(self, frac):
return QRect(self.point_at(frac), self.size())
def abspos(self, widget):
pos = widget.pos()
parent = widget.parent()
while parent is not self.gui:
pos += parent.pos()
parent = parent.parent()
return pos
def start(self):
if config['disable_animations']:
return
self.setVisible(True)
self.raise_()
end = self.abspos(self.gui.jobs_button)
end = QPointF( end.x() + self.gui.jobs_button.width()/3.0, end.y()+20)
start = QPointF(end.x(), end.y() - 0.5*self.height())
self.path = QPainterPath(QPointF(start))
self.path.lineTo(end)
self.path.closeSubpath()
self.animation.setStartValue(self.rect_at(0.0))
self.animation.setEndValue(self.rect_at(1.0))
self.animation.setDirection(self.animation.Backward)
num_keys = 100
for i in xrange(1, num_keys):
i /= num_keys
self.animation.setKeyValueAt(i, self.rect_at(i))
self.animation.start()
def paintEvent(self, ev):
p = QPainter(self)
p.setRenderHints(p.Antialiasing)
p.setBrush(self.brush)
p.setPen(Qt.NoPen)
p.drawPath(self.arrow_path)
p.end()