LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How do you control size and placement of widgets in table under gtk (https://www.linuxquestions.org/questions/programming-9/how-do-you-control-size-and-placement-of-widgets-in-table-under-gtk-668512/)

davimint 09-08-2008 08:50 PM

How do you control size and placement of widgets in table under gtk
 
Hi, I'm trying to learn a little about GUI programing and I'm having problems understanding how to control the placement of widgets in a table. Here's the code of something I'm working on.
Code:

#include <gtk/gtk.h>

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

        GtkWidget *window;
        GtkWidget *calendar;
        GtkWidget *table;
        GtkWidget *combo;
        GtkWidget *button;
       
        GList *items = NULL;
       
        gtk_init(&argc, &argv);

        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(window), "Account Manager Window  ");
        gtk_window_set_default_size(GTK_WINDOW(window), 400, 300);
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

        table = gtk_table_new(3, 3, TRUE);
        gtk_container_add(GTK_CONTAINER(window), table);
        gtk_container_border_width(GTK_CONTAINER(window), 15);

        items = g_list_append(items, "005-Jackson");
        items = g_list_append(items, "011-Birmingham");
        items = g_list_append(items, "018-Greenville");
        items = g_list_append(items, "036-Decater");
        items = g_list_append(items, "039-Hattiesburg");
        items = g_list_append(items, "043-Tupelo");
       
        combo = gtk_combo_new();
        gtk_combo_set_popdown_strings(GTK_COMBO(combo), items);
        gtk_table_attach_defaults(GTK_TABLE(table), combo, 2, 3, 0, 1);

        calendar = gtk_calendar_new();
        gtk_table_attach_defaults(GTK_TABLE(table), calendar, 0, 1, 0, 1);

        button = gtk_button_new_with_label("button");
        gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 0, 1);

        g_signal_connect_swapped(G_OBJECT(window), "destroy",
                        G_CALLBACK(gtk_main_quit), NULL);
       
        gtk_widget_show_all(window);
       
        gtk_main();
       
        return 0;

}

The problem is that the button is the same size as the calendar and the combo box is centered. I want to control the size and placements of the widgets(combo box & button) inside the table. Knowing me I'm going about it all wrong and the table may not be my best option but I'm planning on putting about 9 widgets inside the table(window). Maybe I've explained this well enough. I'm an example kind of person so if you don't mind that would best help me.

Thanks.

PEdroArthur_JEdi 09-10-2008 12:48 PM

I'm not a GUI master but I'll try to help you...

First of all

Your table must not be homogeneous, so the third parameter of gtk_table_new must be FALSE:
table = gtk_table_new(3, 3, FALSE);
You're using gtk_table_attach_default(), so, by default, GtkAttachOptions at xoptions and yoptions will be GTK_EXPAND and GTK_FILL. This will cause the attached widgets to expand to fill all the space allocated to it.

To archive your goal, you must use 0 as xoptions and yoptions. So, you should use gtk_table_attach(). I did this:
gtk_combo_set_popdown_strings(GTK_COMBO(combo), items);
gtk_table_attach(GTK_TABLE(table), combo, 2, 3, 0, 1, FALSE, FALSE, 0, 0);

calendar = gtk_calendar_new();
gtk_table_attach(GTK_TABLE(table), calendar, 0, 1, 0, 3, FALSE, FALSE, 0, 0);

button = gtk_button_new_with_label("button");
gtk_table_attach(GTK_TABLE(table), button, 1, 2, 0, 1, FALSE, FALSE, 0, 0);
Hope I help you!


All times are GMT -5. The time now is 06:13 AM.