Генерация слайд-анимации слева при смене продаж - PullRequest
0 голосов
/ 04 марта 2019

У меня есть следующий код, в котором я пытаюсь сгенерировать слайд анимации слева и показать следующее QMainWindow и закрыть текущий, для которого он использует QPropertyAnimation внутри функции, но здесь это не работает, я оставляю код:

Origin.py

from PyQt5.QtWidgets import QMainWindow,QApplication,QPushButton
from PyQt5 import QtCore
from segunda import MainTwo

class Main(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)


        self.Boton = QPushButton(self)
        self.Boton.setText("Press")
        self.Boton.clicked.connect(self.AnimaFunction)

        self.next = MainTwo()

    def AnimaFunction(self):
        self.anima = QtCore.QPropertyAnimation(self.next.show(),b'geometry')
        self.anima.setDuration(1000)
        self.anima.setStartValue(QtCore.QRect(0,0,0,0))
        self.anima.setEndValue(QtCore.QRect(self.next.geometry()))
        self.anima.start()


app = QApplication([])
m = Main()
m.show()
m.resize(800,600)
app.exec_()

Segunda.py

from PyQt5.QtWidgets import QMainWindow,QApplication,QLabel


class MainTwo(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)


        self.Label = QLabel(self)
        self.Label.setText("Soy la segunda ventana")
        self.Label.resize(200,200)

1 Ответ

0 голосов
/ 04 марта 2019

Вы должны передать окно в QPropertyAnimation, вместо этого вы передаете возвращаемый метод show, который является None, поэтому QPropertyAnimation не будет выполнять свою работу, учитывая, что решение выше:

def AnimaFunction(self):
    self.anima = QtCore.QPropertyAnimation(self.next, b'geometry')
    self.anima.setDuration(1000)
    self.anima.setStartValue(QtCore.QRect(0,0,0,0))
    self.anima.setEndValue(QtCore.QRect(self.next.geometry()))
    self.anima.start()
    self.next.show()
    self.hide()
...