如何对齐GtkTable项目?

时间:2014-11-16 20:47:26

标签: c gtk

您正在尝试为简单文本编辑器创建设置对话框 我想知道如何将标签对齐到左边 这是图像显示它 http://oi59.tinypic.com/2qs5vdx.jpg

这是我的代码

GtkWidget * createSettingsDialog(GtkWidget *textView){

    GtkWidget   *dialog,
                *labelWrap,
                *radioWrapNone,
                *radioWrapWord,
                *labelJustify,
                *radioJustifyLeft,
                *radioJustifyRight,
                *radioJustifyCenter,
                *labelMarginLeft,
                *spinLeftMargin,
                *labelMarginRight,
                *spinRightMargin,
                *table,
                *area;
    GSList  *groupWrap,
            *groupJustify;
    dialog = gtk_dialog_new_with_buttons ("Settings",
                                                 NULL,
                                                 GTK_DIALOG_MODAL,
                                                 GTK_STOCK_OK,
                                                 GTK_RESPONSE_OK,
                                                 GTK_STOCK_APPLY,
                                                 GTK_RESPONSE_APPLY,
                                                 GTK_STOCK_CANCEL,
                                                 GTK_RESPONSE_CANCEL,
                                                 NULL);

    area                =   gtk_dialog_get_content_area (GTK_DIALOG(dialog));
    table               =   gtk_table_new (7,4,TRUE);
    labelWrap           =   gtk_label_new("Wrap text :");
    labelJustify        =   gtk_label_new("justification :");
    labelMarginLeft     =   gtk_label_new("margin left :");
    labelMarginRight    =   gtk_label_new("margin right :");
    radioWrapNone       =   gtk_radio_button_new_with_label (NULL,"wrap none");
    groupWrap           =   gtk_radio_button_get_group (GTK_RADIO_BUTTON(radioWrapNone));
    radioWrapWord       =   gtk_radio_button_new_with_label (groupWrap,"wrap word");
    radioJustifyCenter  =   gtk_radio_button_new_with_label (NULL,"justify center");
    groupJustify        =   gtk_radio_button_get_group (GTK_RADIO_BUTTON(radioJustifyCenter));
    radioJustifyLeft    =   gtk_radio_button_new_with_label (groupJustify,"justify left");
    groupJustify        =   gtk_radio_button_get_group (GTK_RADIO_BUTTON(radioJustifyLeft));
    radioJustifyRight   =   gtk_radio_button_new_with_label (groupJustify,"justify right");
    spinLeftMargin      =   gtk_spin_button_new_with_range (0,10,1);
    spinRightMargin     =   gtk_spin_button_new_with_range (0,10,1);

    gtk_table_attach_defaults (GTK_TABLE(table),labelWrap,0,1,0,1);
    gtk_table_attach_defaults (GTK_TABLE(table),radioWrapNone,1,2,1,2);
    gtk_table_attach_defaults (GTK_TABLE(table),radioWrapWord,2,3,1,2);

    gtk_table_attach_defaults (GTK_TABLE(table),labelJustify,0,1,2,3);
    gtk_table_attach_defaults (GTK_TABLE(table),radioJustifyLeft,1,2,3,4);
    gtk_table_attach_defaults (GTK_TABLE(table),radioJustifyCenter,2,3,3,4);
    gtk_table_attach_defaults (GTK_TABLE(table),radioJustifyRight,3,4,3,4);

    gtk_table_attach_defaults (GTK_TABLE(table),labelMarginLeft,0,1,4,5);
    gtk_table_attach_defaults (GTK_TABLE(table),spinLeftMargin,1,2,4,5);
    gtk_table_attach_defaults (GTK_TABLE(table),labelMarginRight,0,1,5,6);
    gtk_table_attach_defaults (GTK_TABLE(table),spinRightMargin,1,2,5,6);

    gtk_table_set_homogeneous (GTK_TABLE(table),TRUE);
    gtk_box_pack_start (GTK_BOX(area),table,FALSE,FALSE,0);
    gtk_widget_show_all (table);    
    return dialog;
}

我希望你理解我的想法!!!!!

1 个答案:

答案 0 :(得分:0)

要在容器中对齐GtkLabel等小部件,您应该使用GtkAlignment。