I have 5 QGroupboxes, all having a QLabel for video display and a corresponding "View" QPushButton. Whenever a button is clicked, the click is connected to a function, which accepts a timer as argument and starts it and starts another function as a thread which also accepts the same timer and stops it at the end. I have created arrays for all objects first and then done all connections with timers/buttons/groupbox layout etc in a loop.
The problem I am facing is whenever I click a button, the same display lable gets activated and shows the video, rather than the respective lable I want to start with the passed timer.
So, I would like to know where I am going wrong or what is some other way to do it (or something better, I am new to PyQt)
This is the function for the creation of all the things, I can try to post a full reproducible code if anyone wants.
def create_addition_tab(self, num=5):
self.add_multiple_groupbox = QGroupBox("Add multiple")
label_add_id = QLabel("ID")
text_edit_add_id = QLineEdit()
label_add_id.setBuddy(text_edit_add_id)
pushbutton_view = QPushButton("View")
pushbutton_add = QPushButton("Capture")
titles = ['Front','Right', 'Left', 'Up', 'Down']
timers = [QTimer() for i in range(num)]
image_labels = [QLabel() for i in range(num)]
addition_boxes = [QGroupBox(titles[i]) for i in range(num)]
push_buttons = [QPushButton("View") for i in range(num)]
add_box_layouts = [QGridLayout() for i in range(num)]
for ind in range(num):
image_labels[ind].setPixmap(self.defaultpixmap.scaled(100, 100, Qt.KeepAspectRatio, Qt.FastTransformation))
timers[ind].timeout.connect(lambda: self.add_image_tab(timers[ind],image_labels[ind]))
push_buttons[ind].clicked.connect(lambda: self.add_image_to_tab(timers[ind]))
add_box_layouts[ind].addWidget(image_labels[ind],0,0)
add_box_layouts[ind].addWidget(push_buttons[ind],1,0)
addition_boxes[ind].setLayout(add_box_layouts[ind])
add_multiple_groupbox_layout = QGridLayout()
add_multiple_groupbox_layout.addWidget(label_add_id, 0, 0)
add_multiple_groupbox_layout.addWidget(text_edit_add_id, 0, 1)
for idx,i in enumerate(addition_boxes):
add_multiple_groupbox_layout.addWidget(i,1+(idx)//2,idx%2)
add_multiple_groupbox_layout.addWidget(pushbutton_add)
self.add_multiple_groupbox.setLayout(add_multiple_groupbox_layout)