Search code examples
pyqt6

PyQt6 Connecting a slot to a button in QDialogButtonBox


How to connect slots on QDialogButtonBox in PyQt6? I can connect reject and accept signal, but i can't connected another buttons (e.g. Reset).

class Test(QtWidgets.QDialog):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        uic.loadUi("test.ui", self)
        self.buttonBox.accepted.connect(lambda: print(1))
        self.buttonBox.rejected.connect(lambda: print(2))


        # AttributeError: clicked
        self.buttonBox.StandardButton.Reset.clicked.connect(lambda: print(3))

Solution

  • you can use this code

    self.buttonBox.button(QDialogButtonBox.Reset).clicked.connect(self.close)