gtkgtk4

Get calculated size of widget in GTK 4.0


Is it possible to find out the calculated size of a widget, say, GtkButton and when the size changes under GTK 4.0? Ive tried a bunch of different things and none seem to work.

It looks like under GTK 3.0 it was possible to use a size-allocate signal, but that has been removed. I appreciate that this is very rarely needed, but surely there must be some way to know a) when the size has changed and b) what that new allocated size is.


Solution

  • size_allocate is a virtual method now. It is intended to be used only by the widget implementation itself, to assign sizes and locations to its children.

    To get the size of a widget outside size_allocate, you can use get_allocation.

    If you're trying to keep another widget's size synced to the size of your button, you should use a GtkSizeGroup instead.