我有以下代码,我试图在左边生成一个动画幻灯片并显示以下QMainWindow并关闭它在函数中使用QPropertyAnimation的当前版本,但它在这里不起作用我留下代码:
origin.朋友
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_()
S恶棍大.朋友
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)
您必须将窗口传递给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()