PySide2 / QButtonGroup setExclusive not working

52 Views Asked by At

I'm having an issue with QButtonGroup in PySide2. I want to create the QButtonGroup with 2 buttons in order to make only one of them checkable at the same time.

import sys
from PySide2.QtWidgets import (QApplication, QHBoxLayout, QWidget, QButtonGroup, QPushButton)

class Example(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        layout = QHBoxLayout()

        buttonGroup = QButtonGroup()
        buttonGroup.setExclusive(True)

        button1 = QPushButton("button1")
        button1.setCheckable(True)

        button2 = QPushButton("button2")
        button2.setCheckable(True)

        buttonGroup.addButton(button1, 1)
        buttonGroup.addButton(button2, 2)

        layout.addWidget(button1)
        layout.addWidget(button2)

        self.setLayout(layout)
        self.show()

def main():
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

However, the "setExclusive" seems not to be working as I can check (or uncheck) both buttons at the same time. Am I missing something?

EDIT

Code updated with reproducible example

0

There are 0 best solutions below