GTK4 basic guide howto work with alignment, styling, etc


Is there any good guide/docs of API how to do some basic things like widgets alignment (for example, expand a widget to all available space, etc), styling (set background color of widget, etc)?
Any hints are appreciated.

The main place to learn about GTK itself is its extensive documentation. A good place to start would be the documentation of GtkWidget. Look at its available properties, like halign and hexpand. These are also available for vertical alignment, in the form of valign and vexpand.

Styling of GTK widgets is done with CSS. GTK’s implementation is very similar to the common CSS variant that’s used for styling webpages. See the CSS in GTK page for a brief introduction, and the GTK CSS Properties docs for available properties.

I hope this helps!


Thank you for hints,

on styling: there’s only one way and it’s CSS? Is there any API behind using external markup files?

CSS is the go-to way, yes. To dynamically alter styles you can define various CSS classes that you add / remove programatically. If you use libadwaita there’s a bunch of built-in style classes for your convenience. GTK itself also supports some of these, like .suggested-action and .pill.

1 Like

Thank you, with available API and styles from CSS data it comes in handy for now.

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