I have a scroll area which has N buttons in it. I need to know which button was pressed. How can I detect it?
My code:
from PyQt5.QtWidgets import QDialog
from PyQt5.QtWidgets import QApplication, QScrollArea,QHBoxLayout, QGroupBox, QPushButton, QFormLayout
import sys
class MainWindow(QDialog):
def __init__(self):
super().__init__()
self.setGeometry(10, 20, 500, 500)
layout = QHBoxLayout(self)
self.formLayout1 = QFormLayout()
self.groupBox1 = QGroupBox("test")
for i in range(20):
self.formLayout1.insertRow(0, QPushButton(str(i)))
self.groupBox1.setLayout(self.formLayout1)
scroll1 = QScrollArea()
scroll1.setWidget(self.groupBox1)
layout.addWidget(scroll1)
self.show()
if __name__ == '__main__':
App = QApplication(sys.argv)
window = MainWindow()
sys.exit(App.exec())