Dec-19-2016, 09:01 PM
Hello
Have problem with label, trying to show label from another file but so far no luck. here is the code:
main.py
but output is:
[Image: xY3WC]output
[url=http://imgur.com/a/xY3WC][/url]
Have problem with label, trying to show label from another file but so far no luck. here is the code:
main.py
class mainWindow(QtGui.QWidget): Â Â Â def __init__(self): Â Â Â Â Â Â Â Â Â Â Â Â Â Â super(mainWindow, self).__init__() Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.spdBar = SpeedPrg(self) Â Â Â Â Â Â Â Â Â Â Â Â Â Â #QtGui.QFontDatabase.addApplicationFont('/fonts/28_Days_Later.tff') Â Â Â Â Â Â Â self.initUi() Â Â Â def initUi(self): Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.spdBar.setGeometry(10, 10, 300, 300) Â Â Â Â Â Â Â self.spdBar.setValue(.8) Â Â Â Â Â Â Â self.spdBar.setSpeedText('textas') Â Â Â Â Â Â Â Â Â Â Â Â Â Â # self.showFullScreen() Â Â Â Â Â Â Â pal = QPalette() Â Â Â Â Â Â Â pal.setColor(QPalette.Background, QtCore.Qt.black) Â Â Â Â Â Â Â self.setPalette(pal) Â Â Â Â Â Â Â self.setGeometry(100, 100, 800, 480) Â Â Â Â Â Â Â self.setWindowTitle('Window Title')and here is second file with label in it:
class SpeedPrg(QtGui.QWidget):    def __init__(self, parent=None):        super(SpeedPrg, self).__init__(parent)               self.lineWidth = 0        self.setValue(0.0)    def setValue(self, val):        val = float(min(max(val, 0), 1))        self._value = -270 * val        self.update()    def setLineWidth(self, lineWidth):        self.lineWidth = lineWidth           def setSpeedText(self, speedTxt):               r = QtCore.QRect(self.rect())                              #get rectangle size        p = r.center()                                             #get rect center               lbl = QtGui.QLabel()        lbl.setGeometry(p.x(),p.y(),50,50)                         #set label geometry        lbl.setText(speedTxt)                                      #set label text        lbl.setFont(QtGui.QFont('SansSerif',24))                   #set font        pall = QtGui.QPalette()        pall.setColor(QtGui.QPalette.WindowText, QtCore.Qt.white)  #set lable color        lbl.setPalette(pall)        print lbl.text()How you can see I trying to call setSpeedText function from main.py (not sure I doing right or wrong, but I trying)
but output is:
[Image: xY3WC]output
[url=http://imgur.com/a/xY3WC][/url]