Gtk.StyleContext¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w |
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
parent_object |
r |
Class Details¶
- class Gtk.StyleContext(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
GtkStyleContext
stores styling information affecting a widget.In order to construct the final style information,
GtkStyleContext
queries information from all attachedGtkStyleProviders
. 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 aGdkDisplay
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 theGtk.STYLE_PROVIDER_PRIORITY_FALLBACK
priority, either aGtkCssProvider
or a custom object implementing theGtkStyleProvider
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 theGtk.STYLE_PROVIDER_PRIORITY_APPLICATION
priority, keep in mind that the user settings inXDG_CONFIG_HOME/gtk-4.0/gtk.css
will still take precedence over your changes, as it uses theGtk.STYLE_PROVIDER_PRIORITY_USER
priority.Deprecated since version 4.10: The relevant API has been moved to [class`Gtk`.Widget] where applicable; otherwise, there is no replacement for querying the style machinery. Stylable UI elements should use widgets.
- classmethod add_provider_for_display(display, provider, priority)[source]¶
- Parameters:
display (
Gdk.Display
) – aGdkDisplay
provider (
Gtk.StyleProvider
) – aGtkStyleProvider
priority (
int
) – 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 betweenGtk.STYLE_PROVIDER_PRIORITY_FALLBACK
andGtk.STYLE_PROVIDER_PRIORITY_USER
Adds a global style provider to display, which will be used in style construction for all
GtkStyleContexts
under display.GTK uses this to make styling information from
GtkSettings
available.Note: If both priorities are the same, A
GtkStyleProvider
added through [method`Gtk`.StyleContext.add_provider] takes precedence over another added through this function.
- classmethod remove_provider_for_display(display, provider)[source]¶
- Parameters:
display (
Gdk.Display
) – aGdkDisplay
provider (
Gtk.StyleProvider
) – aGtkStyleProvider
Removes provider from the global style providers list in display.
- add_class(class_name)[source]¶
- Parameters:
class_name (
str
) – class name to use in styling
Adds a style class to self, 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 { … } ``
Deprecated since version 4.10: Use [method`Gtk`.Widget.add_css_class] instead
- add_provider(provider, priority)[source]¶
- Parameters:
provider (
Gtk.StyleProvider
) – aGtkStyleProvider
priority (
int
) – 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 betweenGtk.STYLE_PROVIDER_PRIORITY_FALLBACK
andGtk.STYLE_PROVIDER_PRIORITY_USER
Adds a style provider to self, to be used in style construction.
Note that a style provider added by this function only affects the style of the widget to which self 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].Deprecated since version 4.10: Use style classes instead
- get_border()[source]¶
- Returns:
return value for the border settings
- Return type:
border:
Gtk.Border
Gets the border for a given state as a
GtkBorder
.Deprecated since version 4.10: This api will be removed in GTK 5
- get_color()[source]¶
- Returns:
return value for the foreground color
- Return type:
color:
Gdk.RGBA
Gets the foreground color for a given state.
Deprecated since version 4.10: Use [method`Gtk`.Widget.get_color] instead
- get_display()[source]¶
- Returns:
a
GdkDisplay
.- Return type:
Returns the
GdkDisplay
to which self is attached.Deprecated since version 4.10: Use [method`Gtk`.Widget.get_display] instead
- get_margin()[source]¶
- Returns:
return value for the margin settings
- Return type:
margin:
Gtk.Border
Gets the margin for a given state as a
GtkBorder
.Deprecated since version 4.10: This api will be removed in GTK 5
- get_padding()[source]¶
- Returns:
return value for the padding settings
- Return type:
padding:
Gtk.Border
Gets the padding for a given state as a
GtkBorder
.Deprecated since version 4.10: This api will be removed in GTK 5
- get_scale()[source]¶
- Returns:
the scale
Deprecated 4.10: Use [method`Gtk`.Widget.get_scale_factor] instead
- Return type:
Returns the scale used for assets.
- get_state()[source]¶
- Returns:
the state flags
- Return type:
Returns the state used for style matching.
This method should only be used to retrieve the
GtkStateFlags
to pass toGtkStyleContext
methods, like [method`Gtk`.StyleContext.get_padding]. If you need to retrieve the current state of aGtkWidget
, use [method`Gtk`.Widget.get_state_flags].Deprecated since version 4.10: Use [method`Gtk`.Widget.get_state_flags] instead
- has_class(class_name)[source]¶
- Parameters:
class_name (
str
) – a class name- Returns:
True
if self has class_name defined- Return type:
Returns
True
if self currently has defined the given class name.Deprecated since version 4.10: Use [method`Gtk`.Widget.has_css_class] instead
- lookup_color(color_name)[source]¶
- Parameters:
color_name (
str
) – color name to lookup- Returns:
True
if color_name was found and resolved,False
otherwise- color:
Return location for the looked up color
- Return type:
Looks up and resolves a color name in the self color map.
Deprecated since version 4.10: This api will be removed in GTK 5
- remove_class(class_name)[source]¶
- Parameters:
class_name (
str
) – class name to remove
Removes class_name from self.
Deprecated since version 4.10: Use [method`Gtk`.Widget.remove_css_class] instead
- remove_provider(provider)[source]¶
- Parameters:
provider (
Gtk.StyleProvider
) – aGtkStyleProvider
Removes provider from the style providers list in self.
Deprecated since version 4.10.
- restore()[source]¶
Restores self state to a previous stage.
See [method`Gtk`.StyleContext.save].
Deprecated since version 4.10: This API will be removed in GTK 5
- save()[source]¶
Saves the self 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.
Deprecated since version 4.10: This API will be removed in GTK 5
- set_display(display)[source]¶
- Parameters:
display (
Gdk.Display
) – aGdkDisplay
Attaches self 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.Deprecated since version 4.10: You should not use this api
- set_scale(scale)[source]¶
- Parameters:
scale (
int
) – scale
Sets the scale to use when getting image assets for the style.
Deprecated since version 4.10: You should not use this api
- set_state(flags)[source]¶
- Parameters:
flags (
Gtk.StateFlags
) – state to represent
Sets the state to be used for style matching.
Deprecated since version 4.10: You should not use this api
- to_string(flags)[source]¶
- Parameters:
flags (
Gtk.StyleContextPrintFlags
) – Flags that determine what to print- Returns:
a newly allocated string representing self
- Return type:
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 self. 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.
Deprecated since version 4.10: This api will be removed in GTK 5
- do_changed() virtual¶
Property Details¶
- Gtk.StyleContext.props.display¶
- Name:
display
- Type:
- Default Value:
- Flags: