V
V
vadimeasy2021-12-11 10:50:14
Python
vadimeasy, 2021-12-11 10:50:14

How to implement progress bar in Qt Desinger?

Hello everyone, I came across the fact that there is no good example on the Internet for implementing a progress bar with binding to downloading using Qt5. In my program, I need to make several buttons with downloading files, but I can’t find information anywhere on how exactly the download process can be implemented so that the user sees it. At the moment, I think that my download functions will not work, but I'll attach it anyway.

Other functions are based on this function:

def save_rutoken(link3):
    filename = link3.split('/')[-1]
    print (filename)
    r = requests.get(link3)
    open(filename, 'wb').write(r.content)
    save_rutoken = tk.Label(win, text='Рутокен скачан', fg='green', bg='#80A6FF', font=('Arial',12))
    save_rutoken.pack()
    save_rutoken.place(x=190, y=37)
    p = Process(target=save_rutoken)
    p.start()
    print('something')


link3 is a variable containing the download link.

this is how the interface itself looks visually:
61b45818b0f83360574482.jpeg

interface code:
from multiprocessing import Process
from PyQt5 import QtCore, QtGui, QtWidgets
import requests

link3 = 'https://download.rutoken.ru/Rutoken/Drivers/Current/rtDrivers.exe'

class Ui_UTM(object):
    def setupUi(self, UTM):
        UTM.setObjectName("UTM")
        UTM.resize(547, 303)
        UTM.setSizeGripEnabled(False)
        UTM.setModal(False)
        self.download_rutoken = QtWidgets.QPushButton(UTM)
        self.download_rutoken.setGeometry(QtCore.QRect(20, 10, 121, 51))
        self.download_rutoken.setObjectName("download_rutoken")
        self.download_utm = QtWidgets.QPushButton(UTM)
        self.download_utm.setGeometry(QtCore.QRect(150, 10, 121, 51))
        self.download_utm.setObjectName("download_utm")
        self.download_desktop = QtWidgets.QPushButton(UTM)
        self.download_desktop.setGeometry(QtCore.QRect(280, 10, 121, 51))
        self.download_desktop.setObjectName("download_desktop")
        self.download_vpn = QtWidgets.QPushButton(UTM)
        self.download_vpn.setGeometry(QtCore.QRect(410, 10, 121, 51))
        self.download_vpn.setObjectName("download_vpn")
        self.status_text = QtWidgets.QLabel(UTM)
        self.status_text.setGeometry(QtCore.QRect(190, 90, 141, 31))
        self.status_text.setObjectName("status_text")
        self.proress_to_rutoken = QtWidgets.QProgressBar(UTM)
        self.proress_to_rutoken.setGeometry(QtCore.QRect(20, 70, 131, 23))
        self.proress_to_rutoken.setProperty("value", 24)
        self.proress_to_rutoken.setObjectName("proress_to_rutoken")
        self.proress_to_rutoken_2 = QtWidgets.QProgressBar(UTM)
        self.proress_to_rutoken_2.setGeometry(QtCore.QRect(150, 70, 131, 23))
        self.proress_to_rutoken_2.setProperty("value", 24)
        self.proress_to_rutoken_2.setObjectName("proress_to_rutoken_2")
        self.proress_to_rutoken_3 = QtWidgets.QProgressBar(UTM)
        self.proress_to_rutoken_3.setGeometry(QtCore.QRect(280, 70, 131, 23))
        self.proress_to_rutoken_3.setProperty("value", 24)
        self.proress_to_rutoken_3.setObjectName("proress_to_rutoken_3")
        self.proress_to_rutoken_4 = QtWidgets.QProgressBar(UTM)
        self.proress_to_rutoken_4.setGeometry(QtCore.QRect(410, 70, 131, 23))
        self.proress_to_rutoken_4.setProperty("value", 24)
        self.proress_to_rutoken_4.setObjectName("proress_to_rutoken_4")
        self.pushButton = QtWidgets.QPushButton(UTM)
        self.pushButton.setGeometry(QtCore.QRect(100, 180, 141, 51))
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(UTM)
        self.pushButton_2.setGeometry(QtCore.QRect(300, 180, 141, 51))
        self.pushButton_2.setObjectName("pushButton_2")
        self.status_bar = QtWidgets.QLabel(UTM)
        self.status_bar.setGeometry(QtCore.QRect(20, 119, 521, 41))
        self.status_bar.setText("")
        self.status_bar.setObjectName("status_bar")

        self.retranslateUi(UTM)
        QtCore.QMetaObject.connectSlotsByName(UTM)

        self.add_functions()

    def retranslateUi(self, UTM):
        _translate = QtCore.QCoreApplication.translate
        UTM.setWindowTitle(_translate("UTM", "UTM Настройка"))
        self.download_rutoken.setText(_translate("UTM", "Скачать Рутокен"))
        self.download_utm.setText(_translate("UTM", "Скачать UTM "))
        self.download_desktop.setText(_translate("UTM", "Скачать Desktop DxBx"))
        self.download_vpn.setText(_translate("UTM", "Скачать Open VPN"))
        self.status_text.setText(_translate("UTM", "Статус обработки запроса:"))
        self.pushButton.setText(_translate("UTM", "Настроить Брандмауэр"))
        self.pushButton_2.setText(_translate("UTM", "Перезапустить службы"))

    def add_functions(self):
        self.download_rutoken.clicked.connect(self.rutoken_download)

    def rutoken_download(self):
        filename = link3.split('/')[-1]
        print(filename)
        r = requests.get(link3)
        open(filename, 'wb').write(r.content)
        p = Process(target=self.rutoken_download)
        p.start()
        print('something')

if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    UTM = QtWidgets.QDialog()
    ui = Ui_UTM()
    ui.setupUi(UTM)
    UTM.show()
    sys.exit(app.exec_())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-12-11
@vadimeasy

An example of progress output in Qt is right here . See the requests documentation for an example of load control . Combining it into one program is not tricky.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question