Disable items in wxChoice, or wxComboBox, or other alternative?

1,480 views
Skip to first unread message

ardi

unread,
Apr 13, 2012, 2:23:56 PM4/13/12
to wx-users
Hi,

I'm quite used to applications where a combobox-like control had
disabled items sometimes.

For example, an audio application had a pulldown menu selector for
recording in 8bit, 16bit, and 24bit sound format, and depending on the
audio card in the system, some of such options were enabled/disabled
accordingly.

I've seen pulldowns with disabled items like that example many times,
mainly for selecting capabilities or features which depended on the
hardware.

And I'm also used to put them in my applications when they were Motif-
native.

But I see there's no way of disabling/enabling items in wxChoice nor
wxComboBox. Or maybe is there a hidden way of doing this?

Otherwise, is there any alternative control which would behave like
wxChoice and allow to disable items?

Again, TIA!

ardi

Vadim Zeitlin

unread,
Apr 14, 2012, 6:58:28 AM4/14/12
to wx-u...@googlegroups.com
On Fri, 13 Apr 2012 11:23:56 -0700 (PDT) ardi wrote:

a> I'm quite used to applications where a combobox-like control had
a> disabled items sometimes.

Interesting, I think I've never seen any application with this UI. What's
the point of having disabled items in the combobox anyhow? Why not just
remove them if they can't be used in any case?

a> But I see there's no way of disabling/enabling items in wxChoice nor
a> wxComboBox. Or maybe is there a hidden way of doing this?

No, native controls don't support this under none of the 3 major
platforms.

a> Otherwise, is there any alternative control which would behave like
a> wxChoice and allow to disable items?

You should almost certainly be able to do this with wxComboCtrl as it's
completely customizable. Still, I wonder why to go to all this trouble
instead of simply removing the items that shouldn't be available.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

ardi

unread,
Apr 14, 2012, 9:45:15 AM4/14/12
to wx-users


On Apr 14, 12:58 pm, Vadim Zeitlin <va...@wxwidgets.org> wrote:
> On Fri, 13 Apr 2012 11:23:56 -0700 (PDT) ardi wrote:
>
> a> I'm quite used to applications where a combobox-like control had
> a> disabled items sometimes.
>
>  Interesting, I think I've never seen any application with this UI. What's
> the point of having disabled items in the combobox anyhow? Why not just
> remove them if they can't be used in any case?

Because it's more user-friendly to show (greyed/disabled) options you
can't use right now, but that you could use if some requirement was
met. I think I've read about this in some vendors UI guidelines: it's
not usually good to just hide UI elements, it's better that the user
realizes (i.e: "hey, I could assign an RGB image as a texture for this
material, but it doesn't let me choose it... ah, I remember... it's
because this is a gouraud shader, I need to select a different shader
first"). In this example, if you just hide the "texture" choice for
gouraud shaders, the user won't understand the application as much as
if you disable it.

As I said, I think I've read about this in some UI guidelines: better
grey-out than hide (well, not always of course, there're circumstances
where a hide is better than a grey-out).

> a> But I see there's no way of disabling/enabling items in wxChoice nor
> a> wxComboBox. Or maybe is there a hidden way of doing this?
>
>  No, native controls don't support this under none of the 3 major
> platforms.

I think OSX supports it, and I suppose it's also a way to support it
in Windows and GTK, because I've seen it in several apps. I don't
remember now, but I've seen it.

Anyway, I've written my own wxChoice-derived class which emulates item
disabling, by enclosing disabled items in parentheses. Sure, uglier
than greying them out, but at least I've the functionality, and I also
found this trac ticket with somebody who achieved a hack for true item
disabling, so maybe I can get a better emulation than the parentheses:

http://trac.wxwidgets.org/ticket/11130

Thanks a lot for your comments, Vadim

ardi

Vadim Zeitlin

unread,
Apr 14, 2012, 10:02:55 AM4/14/12
to wx-u...@googlegroups.com
On Sat, 14 Apr 2012 06:45:15 -0700 (PDT) ardi wrote:

a> Because it's more user-friendly to show (greyed/disabled) options you
a> can't use right now, but that you could use if some requirement was
a> met.

IMHO this is wrong. It's nice to see greyed out options if it's clear what
do you need to do to enable them. If it's not -- and I really am not sure
how can it be clear in this case -- then it's better to not show them at
all.

a> > a> But I see there's no way of disabling/enabling items in wxChoice nor
a> > a> wxComboBox. Or maybe is there a hidden way of doing this?
a> >
a> >  No, native controls don't support this under none of the 3 major
a> > platforms.
a>
a> I think OSX supports it,

Yes, you're right, it does when using wxChoice. Not for wxComboBox though.

a> and I suppose it's also a way to support it in Windows and GTK, because
a> I've seen it in several apps. I don't remember now, but I've seen it.

There is, of course, a way to do it, but it's not native.

Reply all
Reply to author
Forward
0 new messages