1

我有以下代码,其中我试图在左侧生成一个动画幻灯片并显示以下 QMainWindow 并关闭它在函数中使用 QPropertyAnimation 的当前窗口,但它在这里不起作用我留下代码:

起源.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_()

西贡达.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)
4

1 回答 1

1

您必须将窗口传递给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()
于 2019-03-04T07:38:32.223 回答