Re: [fltk.general] How do you disable a button?

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
Previous Message ]New Message | Reply ]Next Message ]

Re: How do you disable a button? Greg Ercolano Jan 13, 2022 top right image

On 1/13/22 3:38 AM, 'Mark' via fltk.general wrote:
I have a "history" menubutton that I want to enable when the menu has items and disable when it doesn't. It will start out with no entries and gradually they'll be added depending on what the user does. Similarly, I have other buttons which should be enabled/disabled depending on context.

    If it's a widget, e.g. Fl_Menu_Button, all widgets derive from Fl_Widget where you'll find
    methods like deactivate() (which disables and grays-out the widget), and activate().
    Also show() and hide() which can make a widget appear/disappear.
    That should affect the entire menu button, deactivating it from being pressed.

    If however you're trying to deactivate individual menu items or submenus,
    that's different; you might use e.g. menubutton->find_item("item name here")
    to find the Fl_Menu_Item, and then call item->deactivate() to deactivate it. e.g.

        Fl_Menu_Item *item = (Fl_Menu_Item*)menubutton->find_item("History..");

I've tried setting the trigger to none but that didn't do it.

    Whether or not a widget (or menu item) has a callback() doesn't affect its visible attributes.
    At least not in FLTK, as some buttons/menu items have state that can be polled and not need
    a callback. Also with menus, individual items can leave their callbacks unset, and just set a
    callback for the whole menu, which can be used to determine which item was clicked.

I also tried calling deactivate but that didn't stop clicking it from working.

    Hmm, that should have worked. But see above.

    If that advice doesn't work, we might have to see your code to determine what's wrong.

    Try making a small simple compilable program that creates a window + menubutton
    and then call deactivate() the way you are doing it now, and if it doesn't work, show us the code.


You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Direct Link to Message ]
bottom left image   bottom right image
Previous Message ]New Message | Reply ]Next Message ]

Comments are owned by the poster. All other content is copyright 1998-2023 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to ''.