Basics
Guides
API Reference
Basics
Guides
API Reference
[332:14] static extends: object
Generated metadata helpers for StyleContext class surfaces.
properties ()
Returns property metadata for
StyleContext.
A list.[37:7] extends: object
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 [method@Gtk.StyleContext.add_provider], or
to the display through [func@Gtk.StyleContext.add_provider_for_display]. The
resulting style is a combination of all providers’ information in priority
order. For GTK widgets, any GtkStyleContext returned by
[method@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.
StyleContext (Handle = null)
Creates a new
StyleContextby wrapping a native handle or another wrapper.
Handle is the native handle or another wrapper whose handle to adopt.toNativeHandle (Source)
Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from
fn.call(...), another generated wrapper exposinghandle(), or null. Returns null when the argument carries no pointer.
Source is the raw handle, raw buffer, wrapper, or null.A raw pointer carrier or null when no pointer is present.getLib ()
Returns the opened native library for this generated wrapper.
The opened native library.handle ()
Returns the wrapped NativeHandle.
The wrapped NativeHandle.isNull ()
Returns true when the wrapped handle is null.
A bool.describe ()
Returns a small string for debugging generated wrappers.
A string.asObject ()
Wraps this handle as
Object.
A Object object.getProperty (string Name)
Reads one generated property by name.
setProperty (string Name, Value)
Writes one generated property by name.
setDisplay (object Value)
The display of the style context.
Value is the new property value.None.add_class (string class_name)
Adds a style class to @context, so later uses of the style context will make use of this new class for styling. In the CSS file format, a
GtkEntrydefining a “search” class, would be matched by:css entry.search { ... }While any widget defining a “search” class would be matched by:css .search { ... }
class_name is class name to use in styling.None.add_provider (object provider, int priority)
Adds a style provider to @context, to be used in style construction. Note that a style provider added by this function only affects the style of the widget to which @context belongs. If you want to affect the style of all widgets, use [func@Gtk.StyleContext.add_provider_for_display]. Note: If both priorities are the same, a
GtkStyleProvideradded through this function takes precedence over another added through [func@Gtk.StyleContext.add_provider_for_display].
provider is a GtkStyleProvider.priority is the priority of the style provider. The lower it is, the earlier it will be used in the style construction. Typically this will be in the range between %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK and %GTK_STYLE_PROVIDER_PRIORITY_USER.None.get_display ()
Returns the
GdkDisplayto which @context is attached.
get_scale ()
Returns the scale used for assets.
get_state ()
Returns the state used for style matching. This method should only be used to retrieve the
GtkStateFlagsto pass toGtkStyleContextmethods, like [method@Gtk.StyleContext.get_padding]. If you need to retrieve the current state of aGtkWidget, use [method@Gtk.Widget.get_state_flags].
has_class (string class_name)
Returns %TRUE if @context currently has defined the given class name.
class_name is a class name.remove_class (string class_name)
Removes @class_name from @context.
class_name is class name to remove.None.remove_provider (object provider)
Removes @provider from the style providers list in @context.
provider is a GtkStyleProvider.None.restore ()
Restores @context state to a previous stage. See [method@Gtk.StyleContext.save].
None.save ()
Saves the @context state. This allows temporary modifications done through [method@Gtk.StyleContext.add_class], [method@Gtk.StyleContext.remove_class], [method@Gtk.StyleContext.set_state] to be quickly reverted in one go through [method@Gtk.StyleContext.restore]. The matching call to [method@Gtk.StyleContext.restore] must be done before GTK returns to the main loop.
None.set_display (object display)
Attaches @context to the given display. The display is used to add style information from “global” style providers, such as the display's
GtkSettingsinstance. If you are using aGtkStyleContextreturned from [method@Gtk.Widget.get_style_context], you do not need to call this yourself.
display is a GdkDisplay.None.set_scale (int scale)
Sets the scale to use when getting image assets for the style.
scale is scale.None.set_state (string flags)
Sets the state to be used for style matching.
flags is state to represent.None.to_string (string flags)
Converts the style context into a string representation. The string representation always includes information about the name, state, id, visibility and style classes of the CSS node that is backing @context. Depending on the flags, more information may be included. This function is intended for testing and debugging of the CSS implementation in GTK. There are no guarantees about the format of the returned string, it may change.
flags is Flags that determine what to print.
Aussom
Write once. Embed everywhere.
Copyright 2026 Austin Lehman. All rights reserved.