I have built a application which contained multi QComboBox. On change, each one add buttons (about 100) in a grid layout, here a part of the called function:
for x in xrange(1,100):
my_list_shots.append(str(x))
x=2 # line 1 has the menu
y=1 # row
incrementLineX=1 # every 10 we go to line 2 (x+1) and reset incrementLine and y (row) to 1
for i in xrange(1,121):
try:
my_shot_number=my_list_shots[i]
my_shot_number = "%03d"%int(my_shot_number)
self.buttons = QtWidgets.QPushButton(my_shot_number,self)
self.buttons.setStyleSheet("background-color:brown;color:white")
self.buttons.clicked.connect(partial(self.my_open_mov,my_shot_number))
self.my_grid_layout.addWidget(self.buttons,x,y,1,1)
except Exception as e:
self.buttons = QtWidgets.QPushButton("",self)
self.buttons.setEnabled(False)
my_shot_number=""
y=y+1
incrementLineX=incrementLineX+1
if incrementLineX>10:
x=x+1
y=1
incrementLineX = 1
self.buttons.clicked.connect(partial(self.my_open_mov,my_shot_number))
and so on... I worried about the memory, if I keep my window open all day long with many changes, I'll create each time 99 buttons? or not..? How can I properly build my buttons? Do I need to destroy them when I call the function?
In another way, what I want is to replace new buttons by old ones and I don't want to create thousand of buttons if I keep the windows open.
I just need the way to do it.