I want to solve this problem as it will save me a lot of time in both executing codes and retrieving information.The code below show for loop that display a bunch of group boxes and some information inside. What I need is: when I click on one of them , It will send me it's title which it doesn't happen because it always send me the last item in the loop.
from PyQt5.QtWidgets import *
class MyTableWidget(QWidget):
def __init__(self, parent=None):
super(QWidget, self).__init__(parent)
self.layout = QVBoxLayout(self)
self.tabs = QTabWidget()
self.tab1 = QWidget()
self.tab2 = QScrollArea()
self.tabs.addTab(self.tab1, 'Tab 1')
self.tabs.addTab(self.tab2, 'Tab 2')
content_widget = QWidget()
self.tab2.setWidget(content_widget)
flay = QVBoxLayout(content_widget)
self.tab2.setWidgetResizable(True)
nums={1,2,3,4,5,6,7}
#Here the problem
for n in nums :
self.n = QGroupBox(str(n))
flay.addWidget(self.n)
self.n.setCheckable(True)
#this line particularly
self.n.clicked.connect(lambda: self.succ(self.n.title()))
self.layout.addWidget(self.tabs)
self.resize(300, 100)
def succ(self,num):
print("The coming ",num)