gtk_widget_size_allocate(): attempt to allocate widget with width -19 and height 1

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

gtk_widget_size_allocate(): attempt to allocate widget with width -19 and height 1

Franco Broi
Hi

I have an application built using Glade which has a grid inside an
expander, when I expand the expander I get a Gtk-WARNING even though
everything works as expected. Through trial and error I traced the
problem to the left margin set on the grid widget, if it's zero I don't
get a warning.

I tried putting the grid inside a box but setting a margin on the box
has the same problem.

Any ideas how to make the warning go away? It must be grid widget
related because I use expanders a lot but this is the only one with a
grid inside it.

I'm using Gtk 3.14 and here is a snippet of the Glade XML if it helps

   <object class="GtkExpander" id="expander10">
    <property name="visible">True</property>
    <property name="can_focus">True</property>
    <property name="resize_toplevel">True</property>
    <child>
     <object class="GtkGrid" id="grid2">
      <property name="visible">True</property>
      <property name="can_focus">False</property>
      <property name="halign">start</property>
      <property name="valign">start</property>
      <property name="margin_left">20</property>
      <property name="resize_mode">immediate</property>
      <property name="row_spacing">4</property>
      <property name="column_spacing">20</property>

Not a show stopper but annoying.

Cheers,

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: gtk_widget_size_allocate(): attempt to allocate widget with width -19 and height 1

Gtk+ - Apps Dev mailing list

 Hi Franco,


I see "margin-left" is deprecated since version 3.12.

This might work. If you set the container margin of the grid and then individually place your widgets in the locations that you want them,,, hopefully no warnings. I don't get any warnings on GTK3.18. Will something like this work?

Eric

/*
   gcc -Wall expander1.c -o expander1 `pkg-config --cflags --libs gtk+-3.0`
   Tested with GTK3.18 on Ubuntu16.04
*/
#include<gtk/gtk.h>

int main(int argc, char *argv[])
  {
    gtk_init (&argc, &argv);

    GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Expander");
    gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    GtkWidget *check1=gtk_check_button_new_with_label("Check1");
    gtk_widget_set_hexpand(check1, TRUE);
    gtk_widget_set_vexpand(check1, TRUE);

    GtkWidget *check2=gtk_check_button_new_with_label("Check2");
    gtk_widget_set_hexpand(check2, TRUE);
    gtk_widget_set_vexpand(check2, TRUE);
    gtk_widget_set_halign(check2, GTK_ALIGN_CENTER);

    GtkWidget *label=gtk_label_new("Label");
    gtk_widget_set_hexpand(label, TRUE);
    gtk_widget_set_vexpand(label, TRUE);  

    GtkWidget *grid=gtk_grid_new();
    gtk_container_set_border_width(GTK_CONTAINER(grid), 20);
    gtk_grid_attach(GTK_GRID(grid), check1, 0, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(grid), check2, 0, 1, 1, 1);
    gtk_grid_attach(GTK_GRID(grid), label, 0, 2, 1, 1);

    GtkWidget *expander=gtk_expander_new("Expander");
    gtk_container_add(GTK_CONTAINER(expander), grid);  

    gtk_container_add(GTK_CONTAINER(window), expander);

    gtk_widget_show_all(window);

    gtk_main();

    return 0;
  }

 


_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: gtk_widget_size_allocate(): attempt to allocate widget with width -19 and height 1

Franco Broi
Thanks Eric. I tried swapping the margin for border width and now I get
a warning for every item I add to the grid. Plus I don't want a wide
border all around the widget, I just want to add some space on the left.

I see that margin-left has been replaced by margin-start but I don't see
that in the version of Glade I'm using and I'm not convinced that it
would behave any differently.

The solution is to pack the grid into an alignment widget and set the
left padding.

Cheers,

On Mon, 2017-12-04 at 13:55 -0500, [hidden email] wrote:

>  Hi Franco,
>
>
> I see "margin-left" is deprecated since version 3.12.
>
> This might work. If you set the container margin of the grid and then individually place your widgets in the locations that you want them,,, hopefully no warnings. I don't get any warnings on GTK3.18. Will something like this work?
>
> Eric
>
> /*
>    gcc -Wall expander1.c -o expander1 `pkg-config --cflags --libs gtk+-3.0`
>    Tested with GTK3.18 on Ubuntu16.04
> */
> #include<gtk/gtk.h>
>
> int main(int argc, char *argv[])
>   {
>     gtk_init (&argc, &argv);
>
>     GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
>     gtk_window_set_title(GTK_WINDOW(window), "Expander");
>     gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
>     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
>     g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
>
>     GtkWidget *check1=gtk_check_button_new_with_label("Check1");
>     gtk_widget_set_hexpand(check1, TRUE);
>     gtk_widget_set_vexpand(check1, TRUE);
>
>     GtkWidget *check2=gtk_check_button_new_with_label("Check2");
>     gtk_widget_set_hexpand(check2, TRUE);
>     gtk_widget_set_vexpand(check2, TRUE);
>     gtk_widget_set_halign(check2, GTK_ALIGN_CENTER);
>
>     GtkWidget *label=gtk_label_new("Label");
>     gtk_widget_set_hexpand(label, TRUE);
>     gtk_widget_set_vexpand(label, TRUE);  
>
>     GtkWidget *grid=gtk_grid_new();
>     gtk_container_set_border_width(GTK_CONTAINER(grid), 20);
>     gtk_grid_attach(GTK_GRID(grid), check1, 0, 0, 1, 1);
>     gtk_grid_attach(GTK_GRID(grid), check2, 0, 1, 1, 1);
>     gtk_grid_attach(GTK_GRID(grid), label, 0, 2, 1, 1);
>
>     GtkWidget *expander=gtk_expander_new("Expander");
>     gtk_container_add(GTK_CONTAINER(expander), grid);  
>
>     gtk_container_add(GTK_CONTAINER(window), expander);
>
>     gtk_widget_show_all(window);
>
>     gtk_main();
>
>     return 0;
>   }
>
>  
>
>


_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list