红联Linux门户
Linux帮助

gtk+2.0编程中出现问题?

发布时间:2008-12-23 22:27:39来源:红联作者:rukelee
各位,在GTK+2.14中创建好一个toolbar后,发现用gtk_toolbar_set_tooltips()函数后不能够设置添加到toolbar里面button的tooltips,查了下资料发现在2.14版本中这个函数的作用已经取消了,但是有什么更好的办法来设定这个tooltips在鼠标接近时出现或消隐呢?

大家帮个忙~~~
文章评论

共有 1 条评论

  1. rukelee 于 2008-12-24 19:32:37发表:

    源代码就是下面这样的~~

    #include

    GtkWidget * close_button;
    GtkWidget *tooltips_button;

    /*设置tooltips on/off的回掉函数*/
    void toggle_event (GtkWidget *widget,
    gpointer data)
    {
    gtk_toolbar_set_tooltips (GTK_TOOLBAR (data),
    GTK_TOGGLE_BUTTON (widget)->active);
    }

    int main(int argc, char * argv[])
    {
    GtkWidget *dialog;
    GtkWidget *handlebox;
    GtkWidget *toolbar;
    GtkWidget *icon;

    gtk_init (&argc ,&argv);

    dialog = gtk_dialog_new ();
    gtk_window_set_title (GTK_WINDOW(dialog),"GTKTOOLBAR");
    gtk_widget_set_size_request (dialog ,300,100);
    GTK_WINDOW(dialog)->allow_shrink = TRUE;
    g_signal_connect (G_OBJECT(dialog),"delete_event",
    G_CALLBACK(gtk_main_quit),
    NULL);

    gtk_widget_realize(dialog);

    handlebox = gtk_handle_box_new ();
    gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),handlebox,FALSE,FALSE,5);

    toolbar = gtk_toolbar_new();
    gtk_toolbar_set_orientation (GTK_TOOLBAR(toolbar),GTK_ORIENTATION_HORIZONTAL);
    gtk_toolbar_set_style(GTK_TOOLBAR (toolbar),GTK_TOOLBAR_BOTH);
    gtk_container_set_border_width (GTK_CONTAINER (toolbar),5);
    gtk_container_add (GTK_CONTAINER(handlebox),toolbar);

    icon = gtk_image_new_from_file ("gtk.xpm");
    close_button = gtk_toolbar_append_item (GTK_TOOLBAR(toolbar),
    "Close",
    "Close this dialog",
    "Private",
    icon,
    G_CALLBACK(gtk_main_quit),
    NULL);
    gtk_toolbar_append_space (GTK_TOOLBAR(toolbar));

    icon = gtk_image_new_from_file ("gtk.xpm");
    tooltips_button = gtk_toolbar_append_element (GTK_TOOLBAR(toolbar),
    GTK_TOOLBAR_CHILD_TOGGLEBUTTON,
    NULL,
    "Tooltips On/Off",
    "Toolbar with or without tips",
    "Private",
    icon,
    G_CALLBACK(toggle_event),
    toolbar);
    gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(tooltips_button),TRUE);

    gtk_widget_show_all (dialog);

    gtk_main();
    return 0;
    }