Python Forum

Full Version: problems with label
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello

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]