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 » Wed May 22, 2013 12:29 am

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: 14626
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: CheckBox without Label

Post by doublemax » Wed May 22, 2013 8:13 am

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 » Wed May 22, 2013 2:22 pm

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: 14626
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: CheckBox without Label

Post by doublemax » Wed May 22, 2013 2:39 pm

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 » Thu May 23, 2013 3:14 pm

Ok, thanks!

Post Reply