CheckBox without Label

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
drautb
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sat Mar 02, 2013 9:55 pm

CheckBox without Label

Post by drautb »

Howdy all,

I need a Checkbox component, but without a label. I tried just putting "" for the label on a wxCheckBox, but when I click the checkbox, it still highlights this empty area to the side of the checkbox. (At least on Ubuntu.)

After some googling, I found an implementation that someone wrote for a checkbox without a label: http://olecam.online.fr/wxNoLabelCheckBox/

It seems to work great, looks like a checkbox, but no nasty empty highlights to the side.

The downside is that it doesn't seem to fire any events when it is changed. I don't understand how events work super well yet in wxWidgets, but my guess is that this happens because the checkbox inherits from wxStaticBitmap, which dispatches zero events.

So what I would like to accomplish, is to modify this component so that it dispatches a wxEVT_COMMAND_CHECKBOX_CLICKED event, just like the normal wxCheckBox.

I added this to the OnClicked Method:

Code: Select all

wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, GetId());
event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event);
But that doesn't compile, it says that event shadows a parameter. I'm going to keep looking and reading, but does anyone know an immediate/best-practice solution?

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

Re: CheckBox without Label

Post by doublemax »

But that doesn't compile, it says that event shadows a parameter.
Just use a different variable name. "event" probably already exists as parameter to the event handler you're in.
Use the source, Luke!
drautb
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sat Mar 02, 2013 9:55 pm

Re: CheckBox without Label

Post by drautb »

Yep, that's what it was. Silly me.

Is this a good way to do it? To manually trigger the event?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: CheckBox without Label

Post by doublemax »

Is this a good way to do it? To manually trigger the event?
I'd even say it's the best way, because for the calling code it doesn't make any difference if it's a "real" wxCheckbox or your custom control.
Use the source, Luke!
drautb
Earned a small fee
Earned a small fee
Posts: 12
Joined: Sat Mar 02, 2013 9:55 pm

Re: CheckBox without Label

Post by drautb »

Ok, thanks!
Post Reply