When adding an instance of the Gtk# RadioButton
class to a GUI, it is automatically checked ("activated") as the first member of its radio button group.
For Gtk, this has been discussed to some extent in another question, with the main point of the selected answer being that users expect one radio button to be selected at all times.
I do not dispute that.
However, I am automatically generating my user interface in a way so each radio button is linked to a data model, but none of the radio buttons can, at any time, get a reference to any of the other RadioButton
instances. The data model ensures that one radio button is checked at all times.
Beside being sufficient to match user expectations, I consider this good practice, as like this, data integrity is ensured by the data model, not by the GUI.
Unfortunately, Gtk# will automatically check all radio buttons like this, as it considers each radio button to be the first in its group. For adding the various radio buttons to the same group, I would have to pass the first radio button in the group to the constructor of the other radio buttons - which I cannot, as pointed out above, as I do not have any way to get the reference to that first radio button when instantiating the others.
Setting the Active
property of the radio button to false
does not help, nor does invoking the Toggle
method.
Is there any way to suppress this automatical selection, possibly by subclassing and overriding something I could not find yet? Alternatively, is it somehow possible to force a CheckButton
to look like a radio button for this purpose?
If there is really no other solution, I will try and implement the solution suggested in another answer that involves adding a second hidden radio button for each of my radio buttons, but I would find that extremely hacky for production code.
RadioButton
has aToggle()
method, which seems to be the same thing, but it doesn't yield any visible result. Probably, theRadioButton
automatically reestablishes its state. – GarboilRadioButton
exists, it just knows the abstract widget base class. That's the point of the abstract factory pattern. – Garboilstd::map<unsigned int, std::vector<RadioButton>>
(or multimap, if you prefer) for keeping track of all buttons. Probably within the factory... – Toname