Dec-17-2016, 08:57 PM
Hello
First Im new in python and pyqt. I found progress bar py file on the internet and to use this file I should to import to main py file, so I did:
add __init__.py file to src folder as well in root folder
in main.py file I importing > from src.progressbar import prgBar
in main.py file in __init__ function self.someprogressbar = prgBar()
and set value for progress bar, but no luck so far.
here is the main.py code:
P.S. I know this code is a big mess! :)
First Im new in python and pyqt. I found progress bar py file on the internet and to use this file I should to import to main py file, so I did:
add __init__.py file to src folder as well in root folder
in main.py file I importing > from src.progressbar import prgBar
in main.py file in __init__ function self.someprogressbar = prgBar()
and set value for progress bar, but no luck so far.
here is the main.py code:
from PyQt4 import QtGui, QtCore import sys from src.testCprg import cPrg class mainWindow(QtGui.QWidget): def __init__(self): self.otherFile = cPrg(self) super(mainWindow, self).__init__() self.initUI() def initUI(self): self.label = QtGui.QLabel(self) self.label.setText(self.otherFile.textas) self.label.setGeometry(200, 200, 60, 40) self.otherFile.setGeometry(100, 100, 200, 200) self.otherFile.setValue(0.5) self.setGeometry(0, 0, 800, 480) self.setWindowTitle('Window Title') def main(): app = QtGui.QApplication(sys.argv) gui = mainWindow() gui.show() sys.exit(app.exec_()) if __name__ == '__main__': main()and here is progress bar code:
from PyQt4 import QtGui, Qt, QtCore from PyQt4.Qt import QPen import sys class cPrg(QtGui.QWidget): def __init__(self, initialValue=0, parent=None, *args, **kwargs): super(cPrg, self).__init__(parent, *args, **kwargs) self.linewidth = 1 self.setValue(initialValue) self.textas= 'textas cia' def setValue(self, val): val = float(min(max(val, 0), 1)) self._value = -270 * val self.update() def paintEvent(self, e): print 'yoyo' painter = QtGui.QPainter(self) painter.setRenderHint(painter.Antialiasing) rect = e.rect() gauge_rect = QtCore.QRect(rect) size = gauge_rect.size() pos = gauge_rect.center() gauge_rect.moveCenter( QtCore.QPoint(pos.x()-size.width(), pos.y()-size.height()) ) gauge_rect.setSize(size*.9) gauge_rect.moveCenter(pos) startAngle = 270 * 16 # <-- set start angle to draw arc endAngle = -270 * 16 # <-- set end arc angle painter.setPen(QPen(QtGui.QColor('#000000'), 3))#self.lineWidth)) # <-- arc color # painter.setBrush(QtCore.Qt.HorPattern) painter.drawArc(gauge_rect, startAngle, endAngle) # <-- draw arc painter.end() super(cPrg,self).paintEvent(e)Im not sure what is wrong but thinking something about paintevent (in main.py file this paintevent working). So anyone please can tell me what is wrong? thank you
P.S. I know this code is a big mess! :)