如何在Qt设计器中创建动态进度条

时间:2018-06-06 19:11:53

标签: python pyqt qt5 qt-designer

这里我想创建一个动态进度条,例如它以恒定速率达到最大值。任何帮助,将不胜感激。到目前为止我尝试过的事情。

from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(1007, 837)
        self.textBrowser = QtWidgets.QTextBrowser(Dialog)
        self.textBrowser.setGeometry(QtCore.QRect(170, 80, 661, 81))
        self.textBrowser.setObjectName("textBrowser")
        self.progressBar = QtWidgets.QProgressBar(Dialog)
        self.progressBar.setGeometry(QtCore.QRect(330, 320, 261, 32))
        #self.progressBar.setProperty("value", 0)
        self.progressBar.setObjectName("progressBar")
        self.label = QtWidgets.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(210, -10, 691, 471))
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(200, 490, 97, 30))
        self.label_2.setText("")
        self.label_2.setObjectName("label_2")
        self.label.raise_()
        self.textBrowser.raise_()
        self.label_2.raise_()
        self.progressBar.raise_()
        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)


    def bar(self):
        print "here"
        self.completed = 0

        while self.completed < 100:
            self.completed += 0.0000000000  1
            self.progressBar.setValue(self.completed)

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.textBrowser.setHtml(_translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Cantarell\'; font-size:13.75pt; font-weight:400; font-style:normal;\">\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">M-CAD</p>\n"
"<p align=\"center\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">MALARIA COMPUTER AIDED DIAGNOSIS</p></body></html>"))
        self.label.setText(_translate("Dialog", "<html><head/><body><p><img src=\":/newPrefix/drdo-slide.jpg\"/></p></body></html>"))

import test_rc

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    ui.bar()
    Dialog.show()

    sys.exit(app.exec_())

0 个答案:

没有答案