Thyme
September 8th, 2007, 12:50 PM
I'm busy creating a small and simple application that I can use to store information about the herbs I grow. It's my first application and I'm using c and gtk. I'd like to know how to align a widget (textentry, label, button) in a table's cell so that the widget can be aligned left or right in the cell and not center.
Below is a screenshot of the table and the code I used to create the table:
http://www.hobithouse.co.za/alignment.png
The code is:
table = gtk_table_new(5, 2, FALSE);
label = gtk_label_new("Botanical Family (Taxonomic): ");
gtk_table_attach(GTK_TABLE(table), label,0, 1, 0, 1, 0, 0, 0, 0);
gtk_widget_show(label);
textentry = gtk_entry_new();
gtk_entry_set_width_chars(GTK_ENTRY(textentry), 35);
gtk_table_attach(GTK_TABLE(table), textentry, 1, 2, 0, 1, 0, 0, 0, 0);
gtk_widget_show(textentry);
label = gtk_label_new("Therapeutic Effects: ");
gtk_table_attach(GTK_TABLE(table), label,0, 1, 1, 2, 0, 0, 0, 0);
gtk_widget_show(label);
textentry = gtk_entry_new();
gtk_entry_set_width_chars(GTK_ENTRY(textentry), 35);
gtk_table_attach(GTK_TABLE(table), textentry, 1, 2, 1, 2, 0, 0, 0, 0);
gtk_widget_show(textentry);
label = gtk_label_new("Biochemical Constituents: ");
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, 0, 0, 0, 0);
gtk_widget_show(label);
textentry = gtk_entry_new();
gtk_entry_set_width_chars(GTK_ENTRY(textentry), 35);
gtk_table_attach(GTK_TABLE(table), textentry, 1, 2, 2, 3, 0, 0, 0, 0);
gtk_widget_show(textentry);
label = gtk_label_new("Plant Parts (Morphological): ");
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, 0, 0, 0, 0);
gtk_widget_show(label);
hbox = gtk_hbox_new(FALSE, 0);
checkbutton = gtk_check_button_new_with_label("Roots");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Leaves");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Flowers");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 3, 4, 0, 0, 0, 0);
gtk_widget_show(hbox);
hbox = gtk_hbox_new(FALSE, 0);
checkbutton = gtk_check_button_new_with_label("Seeds");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Stems");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Whole Plant");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 4, 5, 0, 0, 0, 0);
gtk_widget_show(hbox);
label = gtk_label_new("Preferred Method of Intake: ");
gtk_table_attach(GTK_TABLE(table), label,0, 1, 5, 6, 0, 0, 0, 0);
gtk_widget_show(label);
hbox = gtk_hbox_new(FALSE, 0);
checkbutton = gtk_check_button_new_with_label("Infusion");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Tincture");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Decoction");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 5, 6, 0, 0, 0, 0);
gtk_widget_show(hbox);
hbox = gtk_hbox_new(FALSE, 0);
checkbutton = gtk_check_button_new_with_label("Juice");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Salve/Cream/Oil");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Bath");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 6, 7, 0, 0, 0, 0);
gtk_widget_show(hbox);
hbox = gtk_hbox_new(FALSE, 0);
checkbutton = gtk_check_button_new_with_label("Poultice Fomentation/Compress");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Capsule");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 7, 8, 0, 0, 0, 0);
gtk_widget_show(hbox);
label = gtk_label_new("Usage Info");
gtk_notebook_insert_page(GTK_NOTEBOOK(notebook), table, label , 2);
gtk_widget_show(table);
So what I'm trying to do is align all the labels on the left-hand side to justify to the right and align all the widgets on the right-hand side to justify to the left (against the labels). The textentry widgets are okay but the "small" widgets like the checkboxes must be justified left.
Any help would indeed be most welcome and appreciated :)
Below is a screenshot of the table and the code I used to create the table:
http://www.hobithouse.co.za/alignment.png
The code is:
table = gtk_table_new(5, 2, FALSE);
label = gtk_label_new("Botanical Family (Taxonomic): ");
gtk_table_attach(GTK_TABLE(table), label,0, 1, 0, 1, 0, 0, 0, 0);
gtk_widget_show(label);
textentry = gtk_entry_new();
gtk_entry_set_width_chars(GTK_ENTRY(textentry), 35);
gtk_table_attach(GTK_TABLE(table), textentry, 1, 2, 0, 1, 0, 0, 0, 0);
gtk_widget_show(textentry);
label = gtk_label_new("Therapeutic Effects: ");
gtk_table_attach(GTK_TABLE(table), label,0, 1, 1, 2, 0, 0, 0, 0);
gtk_widget_show(label);
textentry = gtk_entry_new();
gtk_entry_set_width_chars(GTK_ENTRY(textentry), 35);
gtk_table_attach(GTK_TABLE(table), textentry, 1, 2, 1, 2, 0, 0, 0, 0);
gtk_widget_show(textentry);
label = gtk_label_new("Biochemical Constituents: ");
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, 0, 0, 0, 0);
gtk_widget_show(label);
textentry = gtk_entry_new();
gtk_entry_set_width_chars(GTK_ENTRY(textentry), 35);
gtk_table_attach(GTK_TABLE(table), textentry, 1, 2, 2, 3, 0, 0, 0, 0);
gtk_widget_show(textentry);
label = gtk_label_new("Plant Parts (Morphological): ");
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, 0, 0, 0, 0);
gtk_widget_show(label);
hbox = gtk_hbox_new(FALSE, 0);
checkbutton = gtk_check_button_new_with_label("Roots");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Leaves");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Flowers");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 3, 4, 0, 0, 0, 0);
gtk_widget_show(hbox);
hbox = gtk_hbox_new(FALSE, 0);
checkbutton = gtk_check_button_new_with_label("Seeds");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Stems");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Whole Plant");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 4, 5, 0, 0, 0, 0);
gtk_widget_show(hbox);
label = gtk_label_new("Preferred Method of Intake: ");
gtk_table_attach(GTK_TABLE(table), label,0, 1, 5, 6, 0, 0, 0, 0);
gtk_widget_show(label);
hbox = gtk_hbox_new(FALSE, 0);
checkbutton = gtk_check_button_new_with_label("Infusion");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Tincture");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Decoction");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 5, 6, 0, 0, 0, 0);
gtk_widget_show(hbox);
hbox = gtk_hbox_new(FALSE, 0);
checkbutton = gtk_check_button_new_with_label("Juice");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Salve/Cream/Oil");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Bath");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 6, 7, 0, 0, 0, 0);
gtk_widget_show(hbox);
hbox = gtk_hbox_new(FALSE, 0);
checkbutton = gtk_check_button_new_with_label("Poultice Fomentation/Compress");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
checkbutton = gtk_check_button_new_with_label("Capsule");
gtk_box_pack_start(GTK_BOX(hbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show(checkbutton);
gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 7, 8, 0, 0, 0, 0);
gtk_widget_show(hbox);
label = gtk_label_new("Usage Info");
gtk_notebook_insert_page(GTK_NOTEBOOK(notebook), table, label , 2);
gtk_widget_show(table);
So what I'm trying to do is align all the labels on the left-hand side to justify to the right and align all the widgets on the right-hand side to justify to the left (against the labels). The textentry widgets are okay but the "small" widgets like the checkboxes must be justified left.
Any help would indeed be most welcome and appreciated :)