本文整理汇总了Python中PyQt4.QtCore.QTimeLine.setCurveShape方法的典型用法代码示例。如果您正苦于以下问题:Python QTimeLine.setCurveShape方法的具体用法?Python QTimeLine.setCurveShape怎么用?Python QTimeLine.setCurveShape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QTimeLine
的用法示例。
在下文中一共展示了QTimeLine.setCurveShape方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ParallaxSlide
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import setCurveShape [as 别名]
class ParallaxSlide(QGraphicsView):
def __init__(self):
QGraphicsView.__init__(self)
self.ofs = 0
self.factor = 1
self.scene = QGraphicsScene()
self.background = None
self.icons = []
self.iconTimeLine = QTimeLine()
self.backgroundTimeLine = QTimeLine()
self.setScene(self.scene)
self.background = self.scene.addPixmap(QPixmap(":/background.jpg"))
self.background.setZValue(0.0)
self.background.setPos(0, 0)
for i in range(7):
str = QString(":/icon%1.png").arg(i+1)
icon = self.scene.addPixmap(QPixmap(str))
icon.setPos(320+i*64, 400)
icon.setZValue(1.0)
self.icons.append(icon)
self.setFixedSize(320, 480)
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.connect(self.iconTimeLine, SIGNAL("frameChanged(int)"), self, SLOT("moveIcons(int)"))
self.iconTimeLine.setCurveShape(QTimeLine.EaseInOutCurve)
self.connect(self.backgroundTimeLine, SIGNAL("frameChanged(int)"), self, SLOT("moveBackground(int)"))
self.connect(self.backgroundTimeLine, SIGNAL("finished()"), self, SLOT("adjustParameters()"))
self.backgroundTimeLine.setCurveShape(QTimeLine.EaseInOutCurve)
self.controls = Ui_ControlsForm()
toolWidget = QWidget(self)
toolWidget.setWindowFlags(Qt.Tool | Qt.WindowTitleHint)
self.controls.setupUi(toolWidget)
toolWidget.show()
self.connect(self.controls.speedSlider, SIGNAL("valueChanged(int)"),
self, SLOT("adjustParameters()"))
self.connect(self.controls.normalButton, SIGNAL("clicked()"),
self, SLOT("adjustParameters()"))
self.connect(self.controls.parallaxButton, SIGNAL("clicked()"),
self, SLOT("adjustParameters()"))
self.connect(self.controls.leftButton, SIGNAL("clicked()"),
self, SLOT("slideLeft()"))
self.connect(self.controls.rightButton, SIGNAL("clicked()"),
self, SLOT("slideRight()"))
self.slideBy(-320)
self.adjustParameters()
@pyqtSignature("")
def slideLeft(self):
if self.iconTimeLine.state() != QTimeLine.NotRunning:
return
if self.ofs > -640:
self.slideBy(-320)
@pyqtSignature("")
def slideRight(self):
if self.iconTimeLine.state() != QTimeLine.NotRunning:
return
if self.ofs < 0:
self.slideBy(320)
@pyqtSignature("int")
def slideBy(self, dx):
iconStart = self.ofs
iconEnd = self.ofs + dx
self.iconTimeLine.setFrameRange(iconStart, iconEnd)
self.iconTimeLine.start()
backgroundStart = -320 - int((-320 - iconStart)/self.factor)
backgroundEnd = -320 - int((-320 - iconEnd)/self.factor)
self.backgroundTimeLine.setFrameRange(backgroundStart, backgroundEnd)
self.backgroundTimeLine.start()
self.ofs = iconEnd
@pyqtSignature("bool")
def setParallaxEnabled(self, p):
if p:
self.factor = 2
self.setWindowTitle("Sliding - Parallax mode")
else:
self.factor = 1
self.setWindowTitle("Sliding - Normal mode")
#.........这里部分代码省略.........
示例2: ItemMovel
# 需要导入模块: from PyQt4.QtCore import QTimeLine [as 别名]
# 或者: from PyQt4.QtCore.QTimeLine import setCurveShape [as 别名]
class ItemMovel(QGraphicsWidget):
rectChanged = pyqtSignal()
def __init__(self, moveX=True, moveY=True, rect=QRectF(0, 0, 30, 30), parent=None):
super().__init__(parent)
self._movel = Movel(moveX, moveY, self)
self.installEventFilter(self._movel)
self._newPos = QPointF()
self._oldPos = QPointF()
self._rect = QRectF()
self._newRect = QRectF()
self._oldRect = QRectF()
self._timePos = QTimeLine(1000)
self._timePos.setCurveShape(QTimeLine.EaseInOutCurve)
self._timePos.valueChanged.connect(self._atualizaPos)
self._timeRect = QTimeLine(1000)
self._timeRect.valueChanged.connect(self._atualizaRect)
self.setTamanho(rect)
def setMoveXY(self, x, y):
self._movel.setMoveXY(x, y)
def getRect(self):
return self._rect
def setRect(self, rect):
self._rect = rect
self._atualizaGeometria()
def boundingRect(self):
return self._rect.adjusted(-1, -1, 1, 1)
def altura(self):
return self._newRect.height()
def _atualizaPos(self, t):
# Funcao da curva que parametriza um segmento AB
# C(t) = A + (B - A)*t
pos = self._oldPos + (self._newPos - self._oldPos) * t
self.setPos(pos)
self._atualizaGeometria()
def _atualizaRect(self, t):
oldP1 = self._oldRect.topLeft()
oldP2 = self._oldRect.bottomRight()
newP1 = self._newRect.topLeft()
newP2 = self._newRect.bottomRight()
p1 = oldP1 + (newP1 - oldP1) * t
p2 = oldP2 + (newP2 - oldP2) * t
self.setRect(QRectF(p1, p2))
def _atualizaGeometria(self):
self.setGeometry(QRectF(self.pos(), self.pos() + self._rect.bottomRight()))
def goto(self, pos):
if self.pos() == pos:
return
if self._timePos.state() == QTimeLine.Running:
self._timePos.stop()
self._oldPos = self.pos()
self._newPos = pos
self._timePos.start()
def setTamanho(self, tam):
if self._rect == tam:
return
if self._timeRect.state() == QTimeLine.Running:
self._timeRect.stop()
self._oldRect = self._rect
self._newRect = tam
self._timeRect.start()
self.rectChanged.emit()
def resize(self, size):
if isinstance(size, QRect):
size = size.size()
self.setTamanho(QRectF(0, 0, size.width() - 3, self._newRect.height()))
def paint(self, painter, widget, option):
if self._timePos.state() == QTimeLine.Running:
currentValue = self._timePos.currentValue()
nextValue = self._timePos.valueForTime(self._timePos.currentTime() + 100)
painter.setBrush(QColor(255, 0, 0, (nextValue - currentValue) * 150))
painter.drawRoundedRect(self._rect, 7, 5)