I have a plugin widget with some tabs, and within the tabs a layout of radio buttons as shown below:

enter image description here

I would like to capture the list of active radio buttons within each tab like so: enter image description here

Is there an easy way to do this dynamically for each tab instead of programatically capturing the state of each radio button?

here is the structure of the UI in QT designer if it helps: enter image description here

  • you can find QRadioButton object in each tab self.mytab.findChildren(QtWidgets.QRadioButton) and iterate for get if each radio button is checked or not
    – Fran Raga
    Jun 5, 2019 at 10:26

1 Answer 1


I found a solution which allows to parse the Tabs in a TabWidget and make a dictionnary of all the Radio buttons inside them:

# make a dictionary for each tab and the list of radio buttons in each one
self.dockwidget = Filtres_standards_PDSDockWidget()
TabWidget = self.dockwidget.FilterTabs.children()            
StackedWidgets = [SWidget for SWidget in  TabWidget if isinstance(SWidget,qw.QStackedWidget)][0]
TabsList = [Tab for Tab in StackedWidgets.children() if isinstance(Tab,qw.QWidget)]                
RadioButtonsLists={Tab.objectName() : [RadioButtons for RadioButtons in Tab.children() if isinstance(RadioButtons, qw.QRadioButton)] for Tab in TabsList}

then a fuction that checks which RButtons are checked to build a query:

#A function to check whithin each tab the list of checked radiobuttons and building a query from it   
def querybuilder(RadioButtonsLists):
    for RadioButtonsList in RadioButtonsLists:
        checkedOnRb = ''
        RBListlen = []
        for RadioButton in RadioButtonsLists[RadioButtonsList]:
            if RadioButton.isChecked():
                if len(checkedOnRb)==0:
                    checkedOnRb = RadioButton.text()
                    checkedOnRb += ", " + RadioButton.text()
        if len(RBListlen)>0:
            if len(QueryText)==0:
                QueryText = RadioButtonsList + ' in (' + str(checkedOnRb) + ')'
                QueryText += ' and ' + RadioButtonsList + ' in (' + str(checkedOnRb) + ')'
    return QueryText

def printquery(RadioButtonsLists):

the result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.