Je rencontre un problème lors de l'animation d'une fenêtre QMainWindow. J'essaie de faire une animation "slide" pour un panneau latéral. Cela fonctionne bien si je l'appelle avant le "app.exec" mais en appelant la fonction "animate_out" il semble ne rien faire. Des idées? PS: Vous pouvez annuler le commentaire du code vers le bas pour voir un exemple de ce que je recherche.Utilisation de QProcessAnimation dans la fenêtre principale
Merci
# PYQT IMPORTS
from PyQt4 import QtCore, QtGui
import sys
import UI_HUB
# MAIN HUB CLASS
class HUB(QtGui.QMainWindow, UI_HUB.Ui_HUB):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
self.setCentralWidget(self._Widget)
self.setWindowTitle('HUB - 0.0')
self._Widget.installEventFilter(self)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint)
self.set_size()
self.animate_out()
def set_size(self):
# Finds available and total screen resolution
resolution_availabe = QtGui.QDesktopWidget().availableGeometry()
ava_height = resolution_availabe.height()
self.resize(380, ava_height)
def animate_out(self):
animation = QtCore.QPropertyAnimation(self, "pos")
animation.setDuration(400)
animation.setStartValue(QtCore.QPoint(1920, 22))
animation.setEndValue(QtCore.QPoint(1541, 22))
animation.setEasingCurve(QtCore.QEasingCurve.OutCubic)
animation.start()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
form = HUB()
form.show()
form.raise_()
form.activateWindow()
# Doing the animation here works just fine
# animation = QtCore.QPropertyAnimation(form, "pos")
# animation.setDuration(400)
# animation.setStartValue(QtCore.QPoint(1920, 22))
# animation.setEndValue(QtCore.QPoint(1541, 22))
# animation.setEasingCurve(QtCore.QEasingCurve.OutCubic)
# animation.start()
app.exec_()
Avez-vous oublié d'appeler 'animation.start()' dans votre fonction? – Mailerdaimon
HI @Mailerdaimon, merci d'avoir répondu. Oui, j'ai oublié d'ajouter la ligne "animation.start()" dans l'exemple. Cependant, l'ajouter à mon script semble ne faire aucune différence. – DevilWarrior
Essayez de démarrer l'animation après le constucteur. Je ne sais pas si cela fonctionnerait dans le "showEvent" mais vous pourriez essayer. – Mailerdaimon