mardi 24 mars 2020

How can I make a QCheckBox for (un)checking several QCheckBoxes?

I am writing a subclass of QCheckBox that I would like to display to the user for checking or unchecking a set of existing check boxes. It works by reacting on the toggled(bool) signals of the check boxes.

The "master" check box must be a tristate check box. When some of the "slave" check boxes are checked but not all of them, the master is set to Qt::CheckState::PartiallyChecked.

It doesn't work well enough. Although I want to set the master check box to "partially checked" within my code, the user should not be able to do that. Clicking onto the master check box should completely check all check boxes except if all of them are already checked. In that case it should uncheck them all. Yet, my master check box also switches to the intermediate state when I click onto it.

I guess that I can change that by overriding void QAbstractButton::checkStateSet() and void QAbstractButton::nextCheckState(), but I do not understand the documentation of these methods. What should they do? And how can I override them to get the expected behaviour?




Aucun commentaire:

Enregistrer un commentaire