我正在寻找一种方法来为笔记本标签创建一个小的关闭按钮。这是为 GTK 2.24、GTK 3 和 4 创建大关闭按钮的常用方法:
GtkWidget *head, *content, *image, *btn, *label = gtk_label_new ("Title");
// create empty boxes
#if GTK_CHECK_VERSION (3,0,0)
head = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
content = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
#else
head = gtk_hbox_new (FALSE, 0);
content = gtk_vbox_new (FALSE, 0);
#endif
// add text to box
#if GTK_CHECK_VERSION (4,0,0)
gtk_box_append (GTK_BOX (head), label);
#else
gtk_box_pack_start (GTK_BOX (head), label, FALSE, FALSE, 0);
#endif
// create close button
#if GTK_CHECK_VERSION (4,0,0)
btn = gtk_button_new_from_icon_name ("gtk-close");
gtk_button_set_has_frame (GTK_BUTTON (btn), FALSE);
#else
btn = gtk_button_new ();
gtk_button_set_image (GTK_BUTTON (btn), gtk_image_new_from_icon_name ("gtk-close", GTK_ICON_SIZE_MENU));
gtk_button_set_relief (GTK_BUTTON (btn), GTK_RELIEF_NONE);
#endif
#if GTK_CHECK_VERSION (3,20,0)
gtk_widget_set_focus_on_click (btn, FALSE);
#else
gtk_button_set_focus_on_click (GTK_BUTTON (btn), FALSE);
#endif
// add button to box
#if GTK_CHECK_VERSION (4,0,0)
gtk_box_append (GTK_BOX (head), btn);
#else
gtk_box_pack_start (GTK_BOX (head), btn, FALSE, FALSE, 0);
#endif
#if !GTK_CHECK_VERSION (4,0,0)
gtk_widget_show_all (head);
#endif
// add boxes to notebook
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), content, head);
gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), content, TRUE);
有人有个好主意吗?