I have a problem to set the width of GtkButton(s). When I use gtk_widget_set_size_request(button, width, height)
with width = 40
and height = 40
, I have a wrong width and a good height. See it :
My code :
// On sépare les panneaux :
GtkWidget* commands_drawing_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
GtkWidget* buttons_tabpanel_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
// On met tout sur le container
gtk_container_add(GTK_CONTAINER(container), buttons_tabpanel_box);
gtk_container_add(GTK_CONTAINER(container), commands_drawing_box);
// Boutons
GtkWidget* buttons_grid = gtk_grid_new();
gtk_box_pack_start(GTK_BOX(buttons_tabpanel_box), buttons_grid, TRUE, TRUE, 1);
// Bouton "Nouveau dessin"
GtkWidget* btn_new_drawing_button_box = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
GtkWidget* btn_new_drawing = gtk_button_new();
GtkWidget* btn_new_drawing_image = gtk_image_new_from_file("D:\\Dev\\Icones_32px\\32_newdocument.png");
gtk_button_set_image(GTK_BUTTON(btn_new_drawing), btn_new_drawing_image);
gtk_grid_attach(GTK_GRID(buttons_grid), btn_new_drawing_button_box, 0, 0, 1, 1);
gtk_container_add(GTK_CONTAINER(btn_new_drawing_button_box), btn_new_drawing);
gtk_widget_set_size_request(btn_new_drawing, 40, 40);
And I don't want to use Glade.
Can you found a solution for this ?
The possible cases as to why your button width is wrong is maybe due to the width of the image.The image is greater than 40. in this case the image won't be resized and the button will wrap around the image.
in your code your using GtkButtonBox which make the button layout homogeneous.(as an alternative you could use gtkbox) if you remove that then your code is working fine.
but if you have to use the button-box. then try changing the widget properties. (https://developer.gnome.org/gtk3/stable/GtkButtonBox.html#GtkButtonBox--s-child-min-height)
inside the button padding and min-height will be set to remove those you have to use css
button {
min-width:0px;
padding:0px;
border:0px;
}
To help in your debugging try using gtk-debugger (https://askubuntu.com/questions/597259/how-do-i-open-gtk-inspector)