This sounds like you should be using QRadioButton instead of QCheckBox and put the pairs of buttons into exclusive QButtonGroup. You can design the UI in Qt Designer, but the buttons have to be added to the QButtonGroup using code.I need to detect when specific checkbox is selected, so i can disable opposite checkbox. To prevent user from accidentally selecting opposite checkboxes.
If you have to use QCheckBox, then you can connect all of them to the same slot. Inside the slot, you can determine which check box was changed by using QObject::sender() and doing a qobject_cast< QCheckBox * > to retrieve the actual QCheckBox instance.
To make it easy to determine the matching pairs of check boxes, I would make a QMap< QCheckBox *, QCheckBox * > with all of the pairs added. Once you have the pointer to the check box that was clicked, you can look up the opposite box using the map.
You cannot avoid writing the code to connect the check boxes to the slot or to build the lookup map. I think it is a bad idea to make signal-slot connections in Qt Designer, because then those connections are hidden away in the UI file where you can forget them. When I was first learning Qt, I would do this, and it caused a large number of bugs and difficulty in debugging them because I could not determine why a slot was being called (or called twice) because a connection was hidden inside the UI code.
Bookmarks