StyleContext


Object Hierarchy:

Gtk.StyleContext Gtk.StyleContext Gtk.StyleContext GLib.Object GLib.Object GLib.Object->Gtk.StyleContext

Description:

[ CCode ( type_id = "gtk_style_context_get_type ()" ) ]
public class StyleContext : Object

StyleContext is an object that stores styling information affecting a widget defined by WidgetPath.

In order to construct the final style information, StyleContext queries information from all attached StyleProviders. Style providers can be either attached explicitly to the context through add_provider, or to the screen through add_provider_for_screen. The resulting style is a combination of all providers’ information in priority order.

For GTK+ widgets, any StyleContext returned by get_style_context will already have a WidgetPath, a Screen and RTL/LTR information set. The style context will also be updated automatically if any of these settings change on the widget.

If you are using the theming layer standalone, you will need to set a widget path and a screen yourself to the created style context through set_path and possibly set_screen. See the “Foreign drawing“ example in gtk3-demo.

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.

GTK+ defines macros for a number of style classes.

Style Regions

Widgets can also add regions with flags to their context. This feature is deprecated and will be removed in a future GTK+ update. Please use style classes instead.

GTK+ defines macros for a number of style regions.

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 StyleProvider yourself with the gtk_style_provider_priority_fallback priority, either a CssProvider or a custom object implementing the StyleProvider 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 StyleProvider with the gtk_style_provider_priority_application priority, keep in mind that the user settings in `XDG_CONFIG_HOME/gtk-3.0/gtk.css` will still take precedence over your changes, as it uses the gtk_style_provider_priority_user priority.


Namespace: Gtk
Package: gtk+-3.0

Content:

Properties:

Static methods:

Creation methods:

Methods:

Signals:

Inherited Members: