GTK4 and style properties

In GTK3, widgets had style properties that were query-able via gtk_widget_style_get(). In GTK4 this API is gone, as a lot of these properties have been rolled into CSS.

My question: how does one access these properties? I have been able to handle certain cases like the “expander-size” property by creating GtkImage of an expander, and querying its size. However things like “focus-line-width”, “indicator-size”, “interior-focus”, etc. aren’t easily replaced. How do you access these types of properties in GTK4?

It’s not just the API to get to those properties that has gone in GTK4: the style properties themselves have gone away, so there’s nothing to get. :smile:

Everything that needs a size is either a widget—including child widgets—so it’s themed using standard CSS properties, like min-width or min-height, paddings, outlines, margins, or borders; or is part of the widget itself and cannot be themed.

For instance, the focus ring is a styled using the :focus selector, using outline-offset and outline-width properties.

If it’s now styled via CSS, is it safe to assume then that things like “focus-line-width” will be included in the size returned by gtk_widget_get_preferred_size()?

The “focus-line-width” has been replaced either by a simple border, which contributes to the size of the widget; or by the outline CSS property, and as the CSS spec states:

The outline created with the outline properties is drawn “over” a box, i.e., the outline is always on top, and doesn’t influence the position or size of the box, or of any other boxes. Therefore, displaying or suppressing outlines does not cause reflow.

This means that it’s only drawn, not measured.

In general, if anything contributes to the size of a widget, it’ll be accounted by the values returned by gtk_widget_measure() and gtk_widget_get_preferred_size().

Okay perfect, thank you for your help!

PS: Discourse is quite nifty, +1.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.