How do I change the contents of a qLabel at runtime?

1

Good afternoon everyone! I need each qLinedit row to be numbered in ascending order from 1 to 24, I created a qLabel for this, but I do not know how to make it change the numbering according to each line, I could only print a lot of [i] as shown the image [here] 1 . What can I do?

    self.ql_coords = {}
    self.num = {}
    #nós

    lo_nodes = qg.QGridLayout()
    #no = qg.Qlabel('Node')
    x = qg.QLabel('x:')
    y = qg.QLabel('y:')
    z = qg.QLabel('z:')

    for i in range(0,24):
        self.num[str(i+1)+str(0)] = qg.QLabel('[i]') #cria a qlabel
        lo_nodes.addWidget(self.num[str(i+1)+str(0)], i+1, 0) #adiciona a qlabel ao layout
        for j in range(1,4):
            self.ql_coords[str(i)+str(j)] = qg.QLineEdit() #cria as qlineedits
            lo_nodes.addWidget(self.ql_coords[str(i)+str(j)], i+1, j) #adiciona as qlineedits ao layout
            lo_nodes.addWidget(x, 0, 1) 
            lo_nodes.addWidget(y, 0 ,2) 
            lo_nodes.addWidget(z, 0, 3) 
    
asked by anonymous 18.09.2018 / 23:04

1 answer

0

The parameter passed in QLabel is what will be displayed. So, if you want that number to be displayed, you need to pass that number as a parameter to string . Your code can be changed in the following ways:

If you are using Python 2:

self.num[str(i+1)+str(0)] = qg.QLabel('[%d]' % i+1) #cria a qlabel

If you are using Python 3:

self.num[str(i+1)+str(0)] = qg.QLabel('[{}]'.format(i+1)) #cria a qlabel

If you are using Python 3.6+:

self.num[str(i+1)+str(0)] = qg.QLabel(f'[{i+1}]') #cria a qlabel

I do not know if [] is required in your view. But for the above functions they are not required.

    
19.09.2018 / 03:22