Mateusz Piotrowski Mateusz Piotrowski - 2 months ago 12
C Question

Is it possible to disable, fade or make a button inside a dialog unclickable in GTK?

I have a dialog like this:

GtkWidget *dialog = gtk_dialog_new_with_buttons("Spell Checking", NULL, 0,
GTK_STOCK_OK,
GTK_RESPONSE_ACCEPT,
GTK_STOCK_ADD,
GTK_RESPONSE_APPLY,
GTK_STOCK_CANCEL,
GTK_RESPONSE_REJECT,
NULL);


After adding all the other necessary elements it'll look like this:

Spell Check Dialog

What I want to do is to disable the
OK
button if the list of correct words is empty.

Of course, there are workarounds like creating a dialog:


  • with
    OK
    when then the list is not empty

  • without otherwise



Nevertheless, I would like to know if I can just disable/fade a buttoon and how.

Answer

GTK Widgets usually have a property Sensitive, when it's set to false, the widget grayed out, i.e. an user couldn't interact with it. There's a function for that purpose

void
gtk_widget_set_sensitive (GtkWidget *widget,
                          gboolean sensitive);

Also you could try to set it directly, like myButton->Sensitive = false.