I want to set a GtkPopover widget to fit the size of the composite widget.
I have been reading around and know that in gtk3 you could listen to the size-allocate
signal, but that no longer exists in gtk4. I read in a Q&A thread that it's best to use properties, but GtkWidget and GtkPopover only have width-request
. I tried binding the property and nothing changes.
What would be the right way to size the GtkPopover
?
Widget structure
GtkWidget (BoxLayout)
|-GtkEntry
|-GtkButton
|-GtkPopover
Update:
Thanks to WhiteOwl
comment, size-allocate
has been removed and told to use resize
signal on GtkDrawingArea
and GtkGLArea
. But since it's a pure composite widget this change is more of a hindrance.
.html#adapt-to-gtkwidgets-size-allocation-changes
Have tried getting the size in realize
and map
on GtkWidget
but width returns 0 for get_size
with Horizontal
.
I want to set a GtkPopover widget to fit the size of the composite widget.
I have been reading around and know that in gtk3 you could listen to the size-allocate
signal, but that no longer exists in gtk4. I read in a Q&A thread that it's best to use properties, but GtkWidget and GtkPopover only have width-request
. I tried binding the property and nothing changes.
What would be the right way to size the GtkPopover
?
Widget structure
GtkWidget (BoxLayout)
|-GtkEntry
|-GtkButton
|-GtkPopover
Update:
Thanks to WhiteOwl
comment, size-allocate
has been removed and told to use resize
signal on GtkDrawingArea
and GtkGLArea
. But since it's a pure composite widget this change is more of a hindrance.
https://docs.gtk.org/gtk4/migrating-3to4.html#adapt-to-gtkwidgets-size-allocation-changes
Have tried getting the size in realize
and map
on GtkWidget
but width returns 0 for get_size
with Horizontal
.
- docs.gtk.org/gtk4/… – White Owl Commented Jan 19 at 19:52
- @WhiteOwl sadly it doesn't help, as the widget isn't a GtkDrawingArea. – NebulaFox Commented Jan 20 at 13:15
1 Answer
Reset to default 0I ended up reporting an issue on GTK's gitlab. Turns out I was looking in all the wrong places.
A maintainer replied with
If you are talking about a generic widget and its snapshot() vfunc, the size of the widget (in application units) is available at snapshot time via gtk_widget_get_width() and gtk_widget_get_height(). To go from application units to device pixels requires to factor in transforms and scale. See https://docs.gtk.org/gtk4/coordinates.html#scaling