本文整理匯總了Python中PyQt4.Qt.QPropertyAnimation.setKeyValueAt方法的典型用法代碼示例。如果您正苦於以下問題:Python QPropertyAnimation.setKeyValueAt方法的具體用法?Python QPropertyAnimation.setKeyValueAt怎麽用?Python QPropertyAnimation.setKeyValueAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt4.Qt.QPropertyAnimation
的用法示例。
在下文中一共展示了QPropertyAnimation.setKeyValueAt方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: CoverDelegate
# 需要導入模塊: from PyQt4.Qt import QPropertyAnimation [as 別名]
# 或者: from PyQt4.Qt.QPropertyAnimation import setKeyValueAt [as 別名]
class CoverDelegate(QStyledItemDelegate):
MARGIN = 4
@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, 'animated_size', self)
self.animation.setEasingCurve(QEasingCurve.OutInCirc)
self.animation.setDuration(500)
self.set_dimensions()
self.cover_cache = CoverCache(limit=gprefs['cover_grid_cache_size'])
self.render_queue = Queue()
self.animating = None
self.highlight_color = QColor(Qt.white)
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']
if height < 0.1:
height = max(185, QApplication.instance().desktop().availableGeometry(self.parent()).height() / 5.0)
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)
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.1:
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 paint(self, painter, option, index):
QStyledItemDelegate.paint(self, painter, option, QModelIndex()) # draw the hover and selection highlights
m = index.model()
db = m.db
try:
book_id = db.id(index.row())
except (ValueError, IndexError, KeyError):
return
if book_id in m.ids_to_highlight_set:
painter.save()
try:
painter.setPen(self.highlight_color)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.drawRoundedRect(option.rect, 10, 10, Qt.RelativeSize)
finally:
painter.restore()
db = db.new_api
cdata = self.cover_cache[book_id]
painter.save()
try:
rect = option.rect
rect.adjust(self.MARGIN, self.MARGIN, -self.MARGIN, -self.MARGIN)
if cdata is None or cdata is False:
title = db.field_for('title', book_id, default_value='')
authors = ' & '.join(db.field_for('authors', book_id, default_value=()))
painter.setRenderHint(QPainter.TextAntialiasing, True)
painter.drawText(rect, Qt.AlignCenter|Qt.TextWordWrap, '%s\n\n%s' % (title, authors))
if cdata is False:
self.render_queue.put(book_id)
else:
if self.title_height != 0:
orect = QRect(rect)
rect.setBottom(rect.bottom() - self.title_height)
if self.animating is not None and self.animating.row() == index.row():
cdata = cdata.scaled(cdata.size() * self._animated_size)
dx = max(0, int((rect.width() - cdata.width())/2.0))
dy = max(0, rect.height() - cdata.height())
rect.adjust(dx, dy, -dx, 0)
#.........這裏部分代碼省略.........
示例2: CoverDelegate
# 需要導入模塊: from PyQt4.Qt import QPropertyAnimation [as 別名]
# 或者: from PyQt4.Qt.QPropertyAnimation import setKeyValueAt [as 別名]
class CoverDelegate(QStyledItemDelegate):
MARGIN = 4
@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, 'animated_size', self)
self.animation.setEasingCurve(QEasingCurve.OutInCirc)
self.animation.setDuration(500)
self.set_dimensions()
self.cover_cache = CoverCache(limit=gprefs['cover_grid_cache_size'])
self.render_queue = Queue()
self.animating = None
self.highlight_color = QColor(Qt.white)
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']
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)
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 paint(self, painter, option, index):
QStyledItemDelegate.paint(self, painter, option, QModelIndex()) # draw the hover and selection highlights
m = index.model()
db = m.db
try:
book_id = db.id(index.row())
except (ValueError, IndexError, KeyError):
return
if book_id in m.ids_to_highlight_set:
painter.save()
try:
painter.setPen(self.highlight_color)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.drawRoundedRect(option.rect, 10, 10, Qt.RelativeSize)
finally:
painter.restore()
marked = db.data.get_marked(book_id)
db = db.new_api
cdata = self.cover_cache[book_id]
device_connected = self.parent().gui.device_connected is not None
on_device = device_connected and db.field_for('ondevice', book_id)
painter.save()
right_adjust = 0
try:
rect = option.rect
rect.adjust(self.MARGIN, self.MARGIN, -self.MARGIN, -self.MARGIN)
orect = QRect(rect)
if cdata is None or cdata is False:
title = db.field_for('title', book_id, default_value='')
authors = ' & '.join(db.field_for('authors', book_id, default_value=()))
painter.setRenderHint(QPainter.TextAntialiasing, True)
painter.drawText(rect, Qt.AlignCenter|Qt.TextWordWrap, '%s\n\n%s' % (title, authors))
if cdata is False:
self.render_queue.put(book_id)
else:
if self.title_height != 0:
trect = QRect(rect)
rect.setBottom(rect.bottom() - self.title_height)
#.........這裏部分代碼省略.........
示例3: Pointer
# 需要導入模塊: from PyQt4.Qt import QPropertyAnimation [as 別名]
# 或者: from PyQt4.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 PyQt4.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()