Questions about GtkWidget

  1. How do I change the color of a widget?

    The background color of a widget is determined by the CSS style that applies to it. To change that, you can set style classes on the widget, and provide custom CSS to change the appearance. Such CSS can be loaded with gtk_css_provider_load_from_file() and its variants. See gtk_style_context_add_provider().

  2. How do I change the font of a widget?

    If you want to make the text of a label larger, you can use gtk_label_set_markup():

    gtk_label_set_markup (label, "<big>big tex</big>");
    

    This is preferred for many apps because it’s a relative size to the user’s chosen font size. See g_markup_escape_text() if you are constructing such strings on the fly.

    You can also change the font of a widget by putting

    .my-widget-class {
      font: Sans 30;
    }
    

    in a CSS file, loading it with gtk_css_provider_load_from_file(), and adding the provider with gtk_style_context_add_provider_for_display(). To associate this style information with your widget, set a style class on its GtkStyleContext using gtk_style_context_add_class(). The advantage of this approach is that users can then override the font you have chosen. See the GtkStyleContext documentation for more discussion.

  3. How do I disable/ghost/desensitize a widget?

    In GTK a disabled widget is termed insensitive. See gtk_widget_set_sensitive().