I need to create buttons dynamically in a QMainWindow, and I'm trying it through the RefreshData() Slot function. The point is, despite the function runs and the Buttons are created, they are not linked to QMainWindow!! Buut when I call that function standalone, this Linking works. What could I be doing wrong, can't figure it out. LotOfThanks
array_stations = {}
a = Station("A", 0, 0, 0)
b = Station("B", 50, 50, 0)
c = Station("C", 100, 100, 0)
array_stations[a.ID] = a
array_stations[b.ID] = b
array_stations[c.ID] = c
class GuiView(QtGui.QMainWindow):
def __init__(self):
super(GuiView, self).__init__()
self.initUI()
def initUI(self):
#CONTROLE DE ESTACOES - PARA CONTROLAR SE UMA ESTACAO EH NOVA OU NAO
self.estacoes = {}
#Set timer para atualizar Widget
self.timer2 =QtCore.QTimer()
self.timer2.timeout.connect(self.RefreshData) ### THIS ONE DOESNT ADD THE BUTTONS....
self.timer2.start(2000)
self.RefreshData() ### ... BUT THIS ONE DOES IT!
self.layout = QtGui.QVBoxLayout()
@pyqtSlot()
def RefreshData(self):
print "blabla"
global array_stations
########## ADD OR UPDATE BUTTONS #################
for s in array_stations:
if not s in self.estacoes:
# ADICIONO UM BOTAO A LISTA
self.estacoes[s] = QtGui.QPushButton(s,self)
self.estacoes[s].move(array_stations[s].x,array_stations[s].y)