GTK+中文社区(gtk.awaysoft.com)

 找回密码
 马上加入

QQ登录

只需一步,快速开始

查看: 2952|回复: 0

GTK+中按钮盒(Button Box)使用说明

[复制链接]
  • TA的每日心情
    奋斗
    2016-10-11 09:20
  • 签到天数: 271 天

    连续签到: 1 天

    [LV.8]以坛为家I

    发表于 2011-7-24 19:55:59 | 显示全部楼层 |阅读模式
    转自:http://www.lupaworld.com/tutorial-view-aid-10419.html

    按钮盒(Button Boxes)可以很方便地快速布置一组按钮。它有水平和垂直两种样式。你可以用以下函数创建水平或垂直按钮盒:
    GtkWidget *gtk_hbutton_box_new( void );
    GtkWidget *gtk_vbutton_box_new( void );
    将按钮添加到按钮盒中可以用下面这个通常的函数:
    gtk_container_add (GTK_CONTAINER (button_box), child_widget);
    下面的示例演示了按钮盒的不同布局设置。
    #include
    /* 用指定的参数创建一个按钮盒 */
    GtkWidget *create_bbox( gint horizontal,
    char *title,
    gint spacing,
    gint child_w,
    gint child_h,
    gint layout )
    {
    GtkWidget *frame;
    GtkWidget *bbox;
    GtkWidget *button;
    frame = gtk_frame_new (title);
    if (horizontal)
    bbox = gtk_hbutton_box_new ();
    else
    bbox = gtk_vbutton_box_new ();
    gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
    gtk_container_add (GTK_CONTAINER (frame), bbox);
    /* 设置按钮盒的外观 */
    gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
    gtk_box_set_spacing (GTK_BOX (bbox), spacing);
    /*gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), child_w, child_h);*/
    button = gtk_button_new_from_stock (GTK_STOCK_OK);
    gtk_container_add (GTK_CONTAINER (bbox), button);
    button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
    gtk_container_add (GTK_CONTAINER (bbox), button);
    button = gtk_button_new_from_stock (GTK_STOCK_HELP);
    gtk_container_add (GTK_CONTAINER (bbox), button);
    return frame;
    }
    int main( int   argc,
    char *argv[] )
    {
    static GtkWidget* window = NULL;
    GtkWidget *main_vbox;
    GtkWidget *vbox;
    GtkWidget *hbox;
    GtkWidget *frame_horz;
    GtkWidget *frame_vert;
    /* 初始化 */
    gtk_init (&argc, &argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Button Boxes");
    g_signal_connect (G_OBJECT (window), "destroy",
    G_CALLBACK (gtk_main_quit),
    NULL);
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    main_vbox = gtk_vbox_new (FALSE, 0);
    gtk_container_add (GTK_CONTAINER (window), main_vbox);
    frame_horz = gtk_frame_new ("Horizontal Button Boxes");
    gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10);
    vbox = gtk_vbox_new (FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
    gtk_container_add (GTK_CONTAINER (frame_horz), vbox);
    gtk_box_pack_start (GTK_BOX (vbox),
    create_bbox (TRUE, "Spread (spacing 40)", 40, 85, 20, GTK_BUTTONBOX_SPREAD),
    TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (vbox),
    create_bbox (TRUE, "Edge (spacing 30)", 30, 85, 20, GTK_BUTTONBOX_EDGE),
    TRUE, TRUE, 5);
    gtk_box_pack_start (GTK_BOX (vbox),
    create_bbox (TRUE, "Start (spacing 20)", 20, 85, 20, GTK_BUTTONBOX_START),
    TRUE, TRUE, 5);
    gtk_box_pack_start (GTK_BOX (vbox),
    create_bbox (TRUE, "End (spacing 10)", 10, 85, 20, GTK_BUTTONBOX_END),
    TRUE, TRUE, 5);
    frame_vert = gtk_frame_new ("Vertical Button Boxes");
    gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert, TRUE, TRUE, 10);
    hbox = gtk_hbox_new (FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
    gtk_container_add (GTK_CONTAINER (frame_vert), hbox);
    gtk_box_pack_start (GTK_BOX (hbox),
    create_bbox (FALSE, "Spread (spacing 5)", 5, 85, 20, GTK_BUTTONBOX_SPREAD),
    TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (hbox),
    create_bbox (FALSE, "Edge (spacing 30)", 30, 85, 20, GTK_BUTTONBOX_EDGE),
    TRUE, TRUE, 5);
    gtk_box_pack_start (GTK_BOX (hbox),
    create_bbox (FALSE, "Start (spacing 20)", 20, 85, 20, GTK_BUTTONBOX_START),
    TRUE, TRUE, 5);
    gtk_box_pack_start (GTK_BOX (hbox),
    create_bbox (FALSE, "End (spacing 20)", 20, 85, 20, GTK_BUTTONBOX_END),
    TRUE, TRUE, 5);
    gtk_widget_show_all (window);
    /* 进入事件循环 */
    gtk_main ();
    return 0;
    }
    *滑块验证:
    您需要登录后才可以回帖 登录 | 马上加入

    本版积分规则

    申请友链|Archiver|小黑屋|手机版|GTK+中文社区 ( 粤ICP备13080851号 )

    我要啦免费统计

    GMT+8, 2024-12-22 13:21 , Processed in 0.020741 second(s), 8 queries , Redis On.

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表