Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: StyleContextMeta

[332:14] static extends: object

Generated metadata helpers for StyleContext class surfaces.

Methods

  • properties ()

    Returns property metadata for StyleContext.

    • @r A list.

class: StyleContext

[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.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • StyleContext (Handle = null)

    Creates a new StyleContext by wrapping a native handle or another wrapper.

    • @p 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 exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • asObject ()

    Wraps this handle as Object.

    • @r 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.

    • @p Value is the new property value.
    • @r 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 GtkEntry defining a “search” class, would be matched by: css entry.search { ... } While any widget defining a “search” class would be matched by: css .search { ... }

    • @p class_name is class name to use in styling.
    • @r 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 GtkStyleProvider added through this function takes precedence over another added through [func@Gtk.StyleContext.add_provider_for_display].

    • @p provider is a GtkStyleProvider.
    • @p 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.
    • @r None.
  • get_display ()

    Returns the GdkDisplay to 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 GtkStateFlags to pass to GtkStyleContext methods, like [method@Gtk.StyleContext.get_padding]. If you need to retrieve the current state of a GtkWidget, use [method@Gtk.Widget.get_state_flags].

  • has_class (string class_name)

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

    • @p class_name is a class name.
  • remove_class (string class_name)

    Removes @class_name from @context.

    • @p class_name is class name to remove.
    • @r None.
  • remove_provider (object provider)

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

    • @p provider is a GtkStyleProvider.
    • @r None.
  • restore ()

    Restores @context state to a previous stage. See [method@Gtk.StyleContext.save].

    • @r 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.

    • @r 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 GtkSettings instance. If you are using a GtkStyleContext returned from [method@Gtk.Widget.get_style_context], you do not need to call this yourself.

    • @p display is a GdkDisplay.
    • @r None.
  • set_scale (int scale)

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

    • @p scale is scale.
    • @r None.
  • set_state (string flags)

    Sets the state to be used for style matching.

    • @p flags is state to represent.
    • @r 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.

    • @p flags is Flags that determine what to print.