Resize GTK widget in vbox to C

Well, I have a problem with the small interface that I am doing in GTK.

I have some widgets in the field, exactly three widgets, and I put them in a vbox with gtk_box_pack_start . I resized these widgets using the gtk_widget_set_size_request function, but it does not seem to take effect since the widgets expand to the total vbox width and do not take into account the size that I fixed in the function.

The piece of code that does this:

 enter = gtk_button_new(); gtk_button_set_image(GTK_BUTTON(enter), gtk_image_new_from_file("iconos/submit.png")); gtk_widget_set_size_request(enter, 195, 32); //User,pass login->user = gtk_entry_new(); login->passwd = gtk_entry_new(); gtk_widget_set_size_request(login->user, 195, 32); gtk_widget_set_size_request(login->passwd, 195, 32); gtk_box_pack_start(GTK_BOX(v_box), login->user, FALSE, FALSE, 10); gtk_box_pack_start(GTK_BOX(v_box), login->passwd, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(v_box), enter, FALSE, FALSE, 10); gtk_container_add(GTK_CONTAINER(window), v_box); 

If I put these widgets in alignment, I have no problems, the size is fixed correctly.

Why is this?

+4
source share
1 answer

What do you want to achieve by setting the size? As the documentation says for gtk_widget_set_size_request() ,

Pay attention to the inherent danger of setting a fixed size - themes, translations into other languages, different fonts and user actions can change the corresponding size for this widget. Thus, in principle, it is impossible to rigidly set the size, which will always be correct.

You can specify a widget size request, but this is not the same as setting the size; we can’t always get what we want, and therefore, under certain circumstances, the widget does not get the required size. This is one such case.

GTK is designed in such a way that you do not need to set fixed sizes for widgets. (See the above quote from the documentation.) Usually the best way to achieve what you want.

In this case, put your button in the GtkHButtonBox using gtk_container_add and set the button field in your vertical field with the expand and fill set to FALSE , as you did before.

+2
source

Source: https://habr.com/ru/post/1337163/


All Articles