LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-08-2008, 08:50 PM   #1
davimint
Member
 
Registered: Jan 2006
Distribution: Slackware Current
Posts: 272

Rep: Reputation: 33
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.
 
Old 09-10-2008, 12:48 PM   #2
PEdroArthur_JEdi
LQ Newbie
 
Registered: Jan 2008
Distribution: Slackware | Debian
Posts: 17

Rep: Reputation: 1
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to customize certain Gtk widgets? mutable Linux - Newbie 3 12-18-2007 07:21 AM
New GTK+ Widgets - GtkCellRendererAccel AndrewKrause LQ Articles Discussion 0 07-30-2007 02:07 PM
LXer: New GTK+ Widgets - GtkAssistant LXer Syndicated Linux News 0 06-09-2007 05:16 PM
New GTK+ Widgets - GtkAssistant AndrewKrause LQ Articles Discussion 0 06-09-2007 12:39 PM
extending gtk+-2.0 widgets with c++ markelo Programming 1 03-27-2007 12:39 PM


All times are GMT -5. The time now is 06:42 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration