Skip to content
Advertisement

Iterate through multiple combo boxes in a container pyqt

I’m having a problem with extracting data from multiple comboboxes at once. I have around 10 comboboxes in a container. I could extract the data individual but that would result in repeated code. This is what I have so far but doesn’t seem to work at all:

  def extractData():
     window.survey= window.surveyContainer.currentText()
  for results in window.surveryContainer.children():    
     results.currentTextChanged.connect(extractData)

Advertisement

Answer

First of all you will need to have all the comboboxes you want to access on the same container (in this case I assume it is surveryContainer), then you can do:

for results in window.surveryContainer.findChildren(QComboBox):    
   results.currentTextChanged.connect(extractData)
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement