I've been trying to find a way to do this, but I can not figure out how to do this, contains a progressbar in pyqt4, I want to call the class of the file passing as a parameter a title, something like:
from modules import progressbar
progressbar.ProgressBar("TITULO AQUI")
NOTE: Since it is an activity bar I do not worry about passing the% progress, I will simply leave it active while a certain process is running, Looking forward to feedback from you
from PyQt4 import QtCore
from PyQt4 import QtGui
import time
import sys
import qdarkstyle
class ProgressBar(QtGui.QWidget):
def __init__(self,title):
super(ProgressBar, self).__init__()
layout = QtGui.QGridLayout(self)
self.title = title
label = QtGui.QLabel()
label.setText(self.title)
label.setAlignment(QtCore.Qt.AlignCenter)
layout.addWidget(label)
# Create a progress bar and a button and add them to the main layout
self.progressBar = QtGui.QProgressBar(self)
self.progressBar.setRange(0,1)
layout.addWidget(self.progressBar)
self.myLongTask = TaskThread()
self.myLongTask.taskFinished.connect(self.onFinished)
self.onStart()
def onStart(self):
self.progressBar.setRange(0,0)
self.myLongTask.start()
def onFinished(self):
# Stop the pulsation
self.progressBar.setRange(0,1)
class TaskThread(QtCore.QThread):
taskFinished = QtCore.pyqtSignal()
def run(self):
time.sleep(30)
self.taskFinished.emit()
In my main function progressbar.py
the part that I call progressbar is exactly this:
# -*- coding: utf-8 -*-
import sys, time
from PyQt4.QtGui import QMessageBox, QMainWindow, QApplication
from PyQt4.uic import loadUi
import qdarkstyle
from .modules import tricks
from .modules import progressbar
class PyAuto(QMainWindow):
def __init__(self):
super(PyAuto, self).__init__()
# instances
self.ui = loadUi('Pyauto/views/menu.ui', self)
self.ui.test.clicked.connect(self.test_progressbar)
self.ui.show()
def test_progressbar(self):
window = progressbar.ProgressBar("Test")
window.show()
app.exec_()
if __name__ == '__main__':
app = QApplication(sys.argv)
app.setStyleSheet(qdarkstyle.load_stylesheet(pyside=False)) # set stylesheet dark
myWindow = PyAuto()
app.exec_()