wxOptionButtons: how to make an "option group"? Topic is solved

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
User avatar
Parduz
Experienced Solver
Experienced Solver
Posts: 53
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

wxOptionButtons: how to make an "option group"?

Post by Parduz » Tue Mar 05, 2019 3:22 pm

I'm creating some custom buttons for my "kiosk" app. Some of them have to act like the options in an "option group", so when one is selected, all the others ones must be unselected. Also, i may want that in a group at least one option is always active.
Inspired by old C++Builder6 similar controls, my wxOptionButtons will have a property called "GroupIndex" which if set != 0 means that all the buttons in the same GroupIndex must "react" to selection events generated from other buttons of the same group.

The "immediate" way to do this i can think of is:
in the "click" event of the clicked wxOptionButtons, loop all the children of the button parent, check if they are wxOptionButton, check if they have the same GroupIndex, and finally deselect it.

There's a better way? like an event (carrying some "code" with it) that each container can "raise" and that all of his children have to (or could) react to?
Or an App or system event?

Other ideas?


(using wxWidgets 3.0.4 on Win7 and Debian, if this matters).

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3352
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxOptionButtons: how to make an "option group"?

Post by ONEEYEMAN » Tue Mar 05, 2019 3:35 pm

Hi,
Isn't what you want is called wxRadioBox? And you are reinventing the wheel?

Thank you.

User avatar
Parduz
Experienced Solver
Experienced Solver
Posts: 53
Joined: Fri Jan 30, 2015 1:48 pm
Location: Bologna, Italy

Re: wxOptionButtons: how to make an "option group"?

Post by Parduz » Tue Mar 05, 2019 4:17 pm

Well, some aspects are like the RadioBox, but mine are not radio buttons but graphical ones, and they have not to be in the same container (i mean: they could be on different branches in the hierarchy of a "main" container).
So there's not an "itemlist", there's not a "value" of the group. They're more a serie of "interconnected" buttons.
I don't think i'm reinventing the wheel.

User avatar
doublemax
Moderator
Moderator
Posts: 13873
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxOptionButtons: how to make an "option group"?

Post by doublemax » Tue Mar 05, 2019 4:45 pm

I did something similar once. In the custom button class i kept a static list of all radio buttons (button ctor added itself to the list, dtor removed). And when a radio button was clicked, i just iterated over the list and deselected all with the same group id.
Use the source, Luke!

Post Reply