本文整理匯總了Python中PyQt4.Qt.QPropertyAnimation.start方法的典型用法代碼示例。如果您正苦於以下問題:Python QPropertyAnimation.start方法的具體用法?Python QPropertyAnimation.start怎麽用?Python QPropertyAnimation.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt4.Qt.QPropertyAnimation
的用法示例。
在下文中一共展示了QPropertyAnimation.start方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: CoverView
# 需要導入模塊: from PyQt4.Qt import QPropertyAnimation [as 別名]
# 或者: from PyQt4.Qt.QPropertyAnimation import start [as 別名]
class CoverView(QWidget): # {{{
cover_changed = pyqtSignal(object, object)
cover_removed = pyqtSignal(object)
def __init__(self, vertical, parent=None):
QWidget.__init__(self, parent)
self._current_pixmap_size = QSize(120, 120)
self.vertical = vertical
self.animation = QPropertyAnimation(self, 'current_pixmap_size', self)
self.animation.setEasingCurve(QEasingCurve(QEasingCurve.OutExpo))
self.animation.setDuration(1000)
self.animation.setStartValue(QSize(0, 0))
self.animation.valueChanged.connect(self.value_changed)
self.setSizePolicy(
QSizePolicy.Expanding if vertical else QSizePolicy.Minimum,
QSizePolicy.Expanding)
self.default_pixmap = QPixmap(I('book.png'))
self.pixmap = self.default_pixmap
self.pwidth = self.pheight = None
self.data = {}
self.do_layout()
def value_changed(self, val):
self.update()
def setCurrentPixmapSize(self, val):
self._current_pixmap_size = val
def do_layout(self):
if self.rect().width() == 0 or self.rect().height() == 0:
return
pixmap = self.pixmap
pwidth, pheight = pixmap.width(), pixmap.height()
try:
self.pwidth, self.pheight = fit_image(pwidth, pheight,
self.rect().width(), self.rect().height())[1:]
except:
self.pwidth, self.pheight = self.rect().width()-1, \
self.rect().height()-1
self.current_pixmap_size = QSize(self.pwidth, self.pheight)
self.animation.setEndValue(self.current_pixmap_size)
def show_data(self, data):
self.animation.stop()
same_item = getattr(data, 'id', True) == self.data.get('id', False)
self.data = {'id':data.get('id', None)}
if data.cover_data[1]:
self.pixmap = QPixmap.fromImage(data.cover_data[1])
if self.pixmap.isNull() or self.pixmap.width() < 5 or \
self.pixmap.height() < 5:
self.pixmap = self.default_pixmap
else:
self.pixmap = self.default_pixmap
self.do_layout()
self.update()
if (not same_item and not config['disable_animations'] and
self.isVisible()):
self.animation.start()
def paintEvent(self, event):
canvas_size = self.rect()
width = self.current_pixmap_size.width()
extrax = canvas_size.width() - width
if extrax < 0:
extrax = 0
x = int(extrax/2.)
height = self.current_pixmap_size.height()
extray = canvas_size.height() - height
if extray < 0:
extray = 0
y = int(extray/2.)
target = QRect(x, y, width, height)
p = QPainter(self)
p.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
p.drawPixmap(target, self.pixmap.scaled(target.size(),
Qt.KeepAspectRatio, Qt.SmoothTransformation))
if gprefs['bd_overlay_cover_size']:
sztgt = target.adjusted(0, 0, 0, -4)
f = p.font()
f.setBold(True)
p.setFont(f)
sz = u'\u00a0%d x %d\u00a0'%(self.pixmap.width(), self.pixmap.height())
flags = Qt.AlignBottom|Qt.AlignRight|Qt.TextSingleLine
szrect = p.boundingRect(sztgt, flags, sz)
p.fillRect(szrect.adjusted(0, 0, 0, 4), QColor(0, 0, 0, 200))
p.setPen(QPen(QColor(255,255,255)))
p.drawText(sztgt, flags, sz)
p.end()
current_pixmap_size = pyqtProperty('QSize',
fget=lambda self: self._current_pixmap_size,
fset=setCurrentPixmapSize
)
def contextMenuEvent(self, ev):
#.........這裏部分代碼省略.........
示例2: Pointer
# 需要導入模塊: from PyQt4.Qt import QPropertyAnimation [as 別名]
# 或者: from PyQt4.Qt.QPropertyAnimation import start [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()