[PyQt] Help with QStateMachine and animations

Demetrius Cassidy dcassidy36 at gmail.com
Tue Apr 5 01:05:44 BST 2011


I am trying to animate a QTableView moving off-screen from center (0,0),
which is replaced by a QGroupBox which slides to 0,0 from off-screen inside
my QStackedWidget.

I am using a QStateMachine which contains two states, and basically when the
state 'stateProceeding' is entered, only the QGroupBox is animated - the
QTableView just seems to flash once, then the QStackedWidget index is
changed and QGroupBox is animated. Similarly, when it enters the
stateReleased state, the opposite happens - QTableView is animated, but not
the QGroupBox.

What am I doing wrong? I want these widgets to smoothly animate sliding on
and off-screen depending on the event.

each page is the QWidget page contained inside the QStackedWidget
self.pageQueue contains a QTableView
self.pageRTP contains a QGroupBox

Animation Code:

def _createAnimations(self):
self._stateProceeding = QState()
self._stateReleased = QState()

self._stateMachine = QStateMachine()

# when the signal callReleased is emitted while in the state
stateProceeding, move to state stateReleased
self._stateProceeding.addTransition(self.callReleased, self._stateReleased)

# reverse of the above
self._stateReleased.addTransition(self.callProceeding,
self._stateProceeding)

self._rtpAnimation = QPropertyAnimation(self.pageRTP, "pos")
self._queueAnimation = QPropertyAnimation(self.pageQueue, "pos")
self._rtpAnimation.setEasingCurve(QtCore.QEasingCurve.InOutCubic)
self._queueAnimation.setEasingCurve(QtCore.QEasingCurve.InOutCubic)
self._rtpAnimation.setDuration(600)
self._queueAnimation.setDuration(self._rtpAnimation.duration())


#start at 0,0 and move offscreen towards the right
self._stateProceeding.assignProperty(self.pageQueue, "pos",
QPoint(self.pageQueue.width(), self.pageQueue.y()))

#set QStackedWidget index
self._stateProceeding.assignProperty(self.stackedWidget, "currentIndex",
self.stackedWidget.indexOf(self.pageRTP))

#start offscreen from the left and move towards center
self._stateProceeding.assignProperty(self.pageRTP, "pos", QPoint(0,0))


#start at 0,0 and move offscreen towards the left
self._stateReleased.assignProperty(self.pageQueue, "pos", QPoint(0,0))

#set QStackedWidget index
self._stateReleased.assignProperty(self.stackedWidget, "currentIndex",
self.stackedWidget.indexOf(self.pageQueue))

#start offscreen from the right and move towards center
self._stateReleased.assignProperty(self.pageRTP, "pos",
QPoint(-self.pageRTP.width(), self.pageRTP.y()))


self._stateMachine.addState(self._stateReleased)
self._stateMachine.addState(self._stateProceeding)
self._stateMachine.addDefaultAnimation(self._queueAnimation)
self._stateMachine.addDefaultAnimation(self._rtpAnimation)
self._stateMachine.setGlobalRestorePolicy(QStateMachine.DontRestoreProperties)
self._stateMachine.setInitialState(self._stateReleased)
self._stateMachine.start()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110405/9f6f7883/attachment-0001.html>


More information about the PyQt mailing list