CssProvider

open class CssProvider(pointer: <Error class: unknown class><<Error class: unknown class>>) : StyleProvider

GtkCssProvider is an object implementing the GtkStyleProvider interface for CSS.

It is able to parse CSS-like input in order to style widgets.

An application can make GTK parse a specific CSS style sheet by calling method@Gtk.CssProvider.load_from_file or method@Gtk.CssProvider.load_from_resource and adding the provider with method@Gtk.StyleContext.add_provider or func@Gtk.StyleContext.add_provider_for_display.

In addition, certain files will be read when GTK is initialized. First, the file $XDG_CONFIG_HOME/gtk-4.0/gtk.css is loaded if it exists. Then, GTK loads the first existing file among XDG_DATA_HOME/themes/THEME/gtk-VERSION/gtk-VARIANT.css, $HOME/.themes/THEME/gtk-VERSION/gtk-VARIANT.css, $XDG_DATA_DIRS/themes/THEME/gtk-VERSION/gtk-VARIANT.css and DATADIR/share/themes/THEME/gtk-VERSION/gtk-VARIANT.css, where THEME is the name of the current theme (see the property@Gtk.Settings:gtk-theme-name setting), VARIANT is the variant to load (see the property@Gtk.Settings:gtk-application-prefer-dark-theme setting), DATADIR is the prefix configured when GTK was compiled (unless overridden by the GTK_DATA_PREFIX environment variable), and VERSION is the GTK version number. If no file is found for the current version, GTK tries older versions all the way back to 4.0.

To track errors while loading CSS, connect to the signal@Gtk.CssProvider::parsing-error signal.

Skipped during bindings generation

  • parameter data: guint8

  • method to_string: C function gtk_css_provider_to_string is ignored

Constructors

Link copied to clipboard
constructor()

Returns a newly created GtkCssProvider.

constructor(pointer: <Error class: unknown class><<Error class: unknown class>>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val gtkCssProviderPointer: <Error class: unknown class><<Error class: unknown class>>
Link copied to clipboard
open override val gtkStyleProviderPointer: <Error class: unknown class><<Error class: unknown class>>

Functions

Link copied to clipboard
open fun connectGtkPrivateChanged(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: () -> Unit): <Error class: unknown class>
Link copied to clipboard
fun connectParsingError(connectFlags: <Error class: unknown class> = ConnectFlags(0u), handler: (section: CssSection, <Error class: unknown class>) -> Unit): <Error class: unknown class>

Signals that a parsing error occurred.

Link copied to clipboard
open fun loadFromFile(file: <Error class: unknown class>)

Loads the data contained in @file into @css_provider.

Link copied to clipboard
open fun loadFromPath(path: String)

Loads the data contained in @path into @css_provider.

Link copied to clipboard
open fun loadFromResource(resourcePath: String)

Loads the data contained in the resource at @resource_path into the @css_provider.

Link copied to clipboard
open fun loadNamed(name: String, variant: String? = null)

Loads a theme from the usual theme paths.