QButtonGroups can have checkboxes. But you cannot add them to a QButtonGroup because they do not inherit QAbstractButton.
It would be really nice for some UIs to be able to have a few QGroupBoxes with exclusive checkboxes. That is, you check one and the other QGroupBoxes are automatically unchecked.
In an ideal world, I could do something like this:
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QGroupBox, QWidget, QApplication,
QAbstractButton, QButtonGroup)
class SuperGroup(QGroupBox, QAbstractButton):
def __init__(self, title, parent=None):
super(SuperGroup, self).__init__(title, parent)
self.setCheckable(True)
self.setChecked(False)
class Example(QWidget):
def __init__(self):
super().__init__()
sg1 = SuperGroup(title = 'Super Group 1', parent = self)
sg1.resize(200,200)
sg1.move(20,20)
sg2 = SuperGroup(title = 'Super Group 2', parent = self)
sg2.resize(200,200)
sg2.move(300,20)
self.bgrp = QButtonGroup()
self.bgrp.addButton(sg1)
self.bgrp.addButton(sg2)
self.setGeometry(300, 300, 650, 500)
self.setWindowTitle('SuperGroups!')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
This code fails as soon as you try to add a SuperGroup to the button group. PyQt5 explicitly does not support multiple inheritance. But there are some examples out in the wild, like from this blog.
In this simple example, it would be easy to manage the clicks programmatically. But as you add more group boxes, it gets more messy. Or what if you want a QButtonGroup with buttons, check boxes, and group boxes? Ugh.