Issue
Currently trying to write a function to return the checked radiobutton from a group of radiobuttons in python, but no success so far.
PyQt Gui code:
self.hlw_customer = QtWidgets.QWidget(self.grb_main)
self.hlw_customer.setGeometry(QtCore.QRect(110, 26, 361, 21))
self.hlw_customer.setObjectName("hlw_customer")
self.hlb_customer = QtWidgets.QHBoxLayout(self.hlw_customer)
self.hlb_customer.setContentsMargins(0, 0, 0, 0)
self.hlb_customer.setObjectName("hlb_customer")
self.rdb_customer1 = QtWidgets.QRadioButton(self.hlw_customer)
self.rdb_customer1.setObjectName("rdb_customer1")
self.hlb_customer.addWidget(self.rdb_customer1)
self.rdb_customer2 = QtWidgets.QRadioButton(self.hlw_customer)
self.rdb_customer2.setObjectName("rdb_customer2")
self.hlb_customer.addWidget(self.rdb_customer2)
self.rdb_customer3 = QtWidgets.QRadioButton(self.hlw_customer)
self.rdb_customer3.setChecked(True)
self.rdb_customer3.setObjectName("rdb_customer3")
self.hlb_customer.addWidget(self.rdb_customer3)
self.rdb_customer4 = QtWidgets.QRadioButton(self.hlw_customer)
self.rdb_customer4.setObjectName("rdb_customer4")
self.hlb_customer.addWidget(self.rdb_customer4)
function to find the checked radiobutton:
def find_checked_radiobutton(self):
''' find the checked radiobutton '''
enabled_checkbox = self.hlw_customer.findChildren(QtWidgets.QRadioButton, 'checked')
But sadly this returns []
Solution
Found the solution myself:
self.find_checked_radiobutton(self.hlw_customer.findChildren(QtWidgets.QRadioButton))
def find_checked_radiobutton(self, radiobuttons):
''' find the checked radiobutton '''
for items in radiobuttons:
if items.isChecked():
checked_radiobutton = items.text()
return checked_radiobutton
Answered By - Ken
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.