0

I'm having trouble getting a custom slot to work after a radio button in my QGroupBox is clicked. Here's the relevant part of the code (PySide2)

class ChooseTarget(QtWidgets.QGroupBox):
    def __init__(self, title=None):
        super().__init__(title)
        with open(definitions.JSON_PATH) as j_file:
            names = json.load(j_file)

        self.radios = [QtWidgets.QRadioButton(names['names'][i]) for i in range(11)] 

        self.radios[names['names'].index(names["lastTarget"])].setChecked(True)

        self.layout = QtWidgets.QGridLayout()
        self.button = QtWidgets.QPushButton("Ok")
        self.styleButton()

        self.addToLayout()

    def addToLayout(self): 
        for i in range(11):
            #adding radio buttons to grid layout
            if i < 4:
                self.layout.addWidget(self.radios[i],0,i)
            elif i >= 4 and i < 8:
                self.layout.addWidget(self.radios[i],1, i - 4)
            else:
                self.layout.addWidget(self.radios[i],2, i - 8)
            self.radios[i].clicked.connect(self.handleClick)
        self.layout.addWidget(self.button,2,3)

handleclick for now is just a method with a print, and I verified that it never runs when the radio buttons are clicked. I've tried using the @Slot decorator as well, or the alternative way of connecting sender and receiver with the SIGNAL and SLOT macros.

Edit: The MainWidget class is the one I show in the main.

class MainWidget(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        self.layout = QtWidgets.QVBoxLayout()
        self.layout.addWidget(self.mTableOfOils)
        self.layout.addWidget(self.text)

        self.mRadioButtons = ChooseTarget("Choose the target")

        self.layout.addLayout(self.mRadioButtons.layout)
        self.setLayout(self.layout)

if __name__ == "__main__":
     app = QtWidgets.QApplication([])
     widget = MainWidget()
     widget.resize(800, 600)
     widget.show()

     sys.exit(app.exec_())
Plutone11011
  • 127
  • 3
  • 10

1 Answers1

0

In the MainWidget class I only added the layout of my QGroupBox but didn't add the radio buttons widget to the main layout, now it works as intended

Plutone11011
  • 127
  • 3
  • 10