Search code examples
gtkgtk3

How to get the size of the custom gtk widget?


My gtk_image widget was wrapped in gtkbox, I did all this in anjuta ui builder. I wanted to get the dimensions using the gtk_widget_get_size_request function, but it returned -1. In addition, if the picture is large, it increases the size of the program, so in the first program I wrapped it all in a scroll. Right now I want to make my widget so that the image is scaled depending on the size of the window. For this, I need to know what size of the widget is available for displaying the image. How do i get these sizes?


Solution

  • If you never set a size request, you will get -1 when getting the size request. I imagine you are actually looking for gtk_widget_get_allocated_size(). Also check out width and height allocation. The allocated size is the actual size of the widget, not what the various preferences for the widget are set to.