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



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, cecashon aol com 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;
  } 

 






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]