Geographic Information Systems Asked by Nathan Leenaerts on August 9, 2020
I have a plugin widget with some tabs, and within the tabs a layout of radio buttons as shown below:
I would like to capture the list of active radio buttons within each tab like so:
Is there an easy way to do this dynamically for each tab instead of programatically capturing the state of each radio button?
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):
QueryText=''
for RadioButtonsList in RadioButtonsLists:
checkedOnRb = ''
RBListlen = []
for RadioButton in RadioButtonsLists[RadioButtonsList]:
if RadioButton.isChecked():
RBListlen.append(1)
if len(checkedOnRb)==0:
checkedOnRb = RadioButton.text()
else:
checkedOnRb += ", " + RadioButton.text()
if len(RBListlen)>0:
if len(QueryText)==0:
QueryText = RadioButtonsList + ' in (' + str(checkedOnRb) + ')'
else:
QueryText += ' and ' + RadioButtonsList + ' in (' + str(checkedOnRb) + ')'
return QueryText
def printquery(RadioButtonsLists):
self.dockwidget.label.setText(str(querybuilder(RadioButtonsLists)))
the result:
Answered by Nathan Leenaerts on August 9, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP