Gtk.StyleContext
Description: Reference for Gtk.StyleContext

### Class

# GtkStyleContext

#### Description [src]

    class Gtk.StyleContext : GObject.Object {
      parent_object: GObject
    }

`GtkStyleContext` stores styling information affecting a widget.

In order to construct the final style information, `GtkStyleContext` queries information from all attached `GtkStyleProviders`. Style providers can be either attached explicitly to the context through `gtk_style_context_add_provider()`, or to the display through `gtk_style_context_add_provider_for_display()`. The resulting style is a combination of all providers’ information in priority order.

For GTK widgets, any `GtkStyleContext` returned by `gtk_widget_get_style_context()` will already have a `GdkDisplay` and RTL/LTR information set. The style context will also be updated automatically if any of these settings change on the widget.

# Style Classes

Widgets can add style classes to their context, which can be used to associate different styles by class. The documentation for individual widgets lists which style classes it uses itself, and which style classes may be added by applications to affect their appearance.

# Custom styling in UI libraries and applications

If you are developing a library with custom widgets that render differently than standard components, you may need to add a `GtkStyleProvider` yourself with the `GTK_STYLE_PROVIDER_PRIORITY_FALLBACK` priority, either a `GtkCssProvider` or a custom object implementing the `GtkStyleProvider` interface. This way themes may still attempt to style your UI elements in a different way if needed so.

If you are using custom styling on an applications, you probably want then to make your style information prevail to the theme’s, so you must use a `GtkStyleProvider` with the `GTK_STYLE_PROVIDER_PRIORITY_APPLICATION` priority, keep in mind that the user settings in `XDG_CONFIG_HOME/gtk-4.0/gtk.css` will still take precedence over your changes, as it uses the `GTK_STYLE_PROVIDER_PRIORITY_USER` priority.

#### Ancestors

- GObject

#### Functions

###### gtk_style_context_add_provider_for_display

Adds a global style provider to `display`, which will be used in style construction for all `GtkStyleContexts` under `display`.

###### gtk_style_context_remove_provider_for_display

Removes `provider` from the global style providers list in `display`.

#### Instance methods

###### gtk_style_context_add_class

Adds a style class to `context`, so later uses of the style context will make use of this new class for styling.

###### gtk_style_context_add_provider

Adds a style provider to `context`, to be used in style construction.

###### gtk_style_context_get_border

Gets the border for a given state as a `GtkBorder`.

###### gtk_style_context_get_color

Gets the foreground color for a given state.

###### gtk_style_context_get_display

Returns the `GdkDisplay` to which `context` is attached.

###### gtk_style_context_get_margin

Gets the margin for a given state as a `GtkBorder`.

###### gtk_style_context_get_padding

Gets the padding for a given state as a `GtkBorder`.

###### gtk_style_context_get_scale

Returns the scale used for assets.

###### gtk_style_context_get_state

Returns the state used for style matching.

###### gtk_style_context_has_class

Returns `TRUE` if `context` currently has defined the given class name.

###### gtk_style_context_lookup_color

Looks up and resolves a color name in the `context` color map.

###### gtk_style_context_remove_class

Removes `class_name` from `context`.

###### gtk_style_context_remove_provider

Removes `provider` from the style providers list in `context`.

###### gtk_style_context_restore

Restores `context` state to a previous stage.

###### gtk_style_context_save

Saves the `context` state.

###### gtk_style_context_set_display

Attaches `context` to the given display.

###### gtk_style_context_set_scale

Sets the scale to use when getting image assets for the style.

###### gtk_style_context_set_state

Sets the state to be used for style matching.

###### gtk_style_context_to_string

Converts the style context into a string representation.

##### Methods inherited from GObject (43)

Please see GObject for a full list of methods.

#### Properties

###### Gtk.StyleContext:display

No description available.

#### Signals

##### Signals inherited from GObject (1)

###### GObject.Object::notify

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.

#### Class structure

    struct GtkStyleContextClass {
      GObjectClass parent_class;
      void (* changed) (
        GtkStyleContext* context
      );
      void (* _gtk_reserved1) (
    void
      );
      void (* _gtk_reserved2) (
    void
      );
      void (* _gtk_reserved3) (
    void
      );
      void (* _gtk_reserved4) (
    void
      );

    }

No description available.

###### Class members

`parent_class: GObjectClass`
  No description available.
`changed: void (* changed) ( GtkStyleContext* context )`
  No description available.
`_gtk_reserved1: void (* _gtk_reserved1) ( void )`
  No description available.
`_gtk_reserved2: void (* _gtk_reserved2) ( void )`
  No description available.
`_gtk_reserved3: void (* _gtk_reserved3) ( void )`
  No description available.
`_gtk_reserved4: void (* _gtk_reserved4) ( void )`
  No description available.

#### Virtual methods

###### Gtk.StyleContextClass.changed

No description available.