【问题标题】:Generate Slide animation left wing when changing Sales更改销售时生成幻灯片动画左翼
【发布时间】:2019-03-04 06:23:32
【问题描述】:

我有以下代码,我在其中试图生成一个向左的动画幻灯片并显示以下 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)

【问题讨论】:

    标签: python pyqt5 qpropertyanimation


    【解决方案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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-12
      • 2019-12-06
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多