如何在PySide2 / Qt5中的QLabel上创建简单的无尽滚动动画?

时间:2019-06-16 09:59:35

标签: python animation pyside2

您能帮助在我的代码中发现问题吗?我正在尝试在PySide2中创建一个简单的动画-滚动标签执行无穷循环。

我尝试遵循example并浏览documentation,但是我在python中使用gui的经验很少。

这是我尝试建立时间轴的代码部分:

STYLE_TEAM = "font:bold 28pt \"\"HP Simplified\"\";" + \
            "color:rgb(255, 85, 0)"

STYLE_WI = "background-color:rgb(70, 70, 70);"

STYLE_PROJ = "QPushButton {" + \
            "    color:white;"  + \
            "    font: 75 14pt \"Consolas\";"  + \
            "    border:offset;}"  + \
            "QPushButton:hover {"  + \
            "    background-color:rgb(255, 85, 0);"  + \
            "    color:black;"  + \
            "   filter: blur(20px);}"

from PySide2 import QtCore, QtGui, QtWidgets

class Ui_Form(object):

    def setupUi(self, Form):
            Form.resize(391, 274)
            Form.setStyleSheet(STYLE_WI)
            Form.setWindowTitle(QtWidgets.QApplication.translate("Form", "Project map", None, -1))

            #region PROJECTS
            self.p1 = QtWidgets.QPushButton(Form)
            self.p1.setGeometry(QtCore.QRect(10, 90, 371, 51))
            self.p1.setStyleSheet(STYLE_PROJ)
            self.p1.setText(QtWidgets.QApplication.translate("Form", "button 1", None, -1))


            self.p2 = QtWidgets.QPushButton(Form)
            self.p2.setGeometry(QtCore.QRect(10, 150, 371, 51))
            self.p2.setStyleSheet(STYLE_PROJ)
            self.p2.setText(QtWidgets.QApplication.translate("Form", "button 2", None, -1))


            self.p3 = QtWidgets.QPushButton(Form)
            self.p3.setGeometry(QtCore.QRect(10, 210, 371, 51))
            self.p3.setStyleSheet(STYLE_PROJ)
            self.p3.setText(QtWidgets.QApplication.translate("Form", "button 3", None, -1))
            #endregion


            #region TEAM
            self.team = QtWidgets.QLabel(Form)
            self.team.setGeometry(QtCore.QRect(90, 20, 291, 51))
            self.team.setStyleSheet(STYLE_TEAM)

            self.timeline = QtCore.QTimeLine()
            self.timeline.setCurveShape(QtCore.QTimeLine.LinearCurve)
            self.timeline.valueChanged.connect(self.team.setText)
            self.timeline.setDuration(5000)
            self.timeline.setFrameRange(0, 26)
            self.team.setText("text that exceeds the label width")
            self.timeline.start()
            #endregion

            #region LOGO
            self.label_2 = QtWidgets.QLabel(Form)
            self.label_2.setGeometry(QtCore.QRect(10, 10, 71, 71))
            self.label_2.setText("")
            self.label_2.setPixmap(QtGui.QPixmap("PLACEHOLDER_70.png"))
            #endregion
            QtCore.QMetaObject.connectSlotsByName(Form)                

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Form = QtWidgets.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_()))

我可能在语法上确实很愚蠢。我可以要求指导吗?

0 个答案:

没有答案