GtkNotebook不显示标签标签内容

时间:2016-05-24 05:39:13

标签: gtk3

在具有GtkNotebook和GtkBox作为选项卡标签的应用程序中,选项卡标签可见,但选项卡标签的内容不可见。如何使标签标签的内容可见?

#include <gtk/gtk.h>

int main (int argc, char *argv[])
{
    gtk_init(&argc, &argv);

    GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    GtkWidget* notebook = gtk_notebook_new();
    GtkWidget* page_content = gtk_label_new("Content");
    GtkWidget* tab_label = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
    GtkWidget* label_content_1 = gtk_label_new("Title");
    GtkWidget* label_content_2 = gtk_button_new_with_label("Close");

    gtk_box_pack_start(GTK_BOX(tab_label), label_content_1, TRUE, TRUE, 0);
    gtk_box_pack_end(GTK_BOX(tab_label), label_content_2, FALSE, FALSE, 0);
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page_content, tab_label);
    gtk_container_add(GTK_CONTAINER(window), notebook);

    gtk_widget_show_all(GTK_WIDGET(window));

    gtk_main();
}

enter image description here

1 个答案:

答案 0 :(得分:0)

我通过明确显示GTK_BOX中的小部件并调用gtk_notebook_set_show_tabs来实现它:

#include <gtk-3.0/gtk/gtk.h>

int main (int argc, char *argv[])
{
    gtk_init(&argc, &argv);

    GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    GtkWidget* notebook = gtk_notebook_new();
    GtkWidget* page_content = gtk_label_new("Content");
    GtkWidget* tab_label = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
    GtkWidget* label_content_1 = gtk_label_new("Title");
    GtkWidget* label_content_2 = gtk_button_new_with_label("Close");

    gtk_widget_show(GTK_WIDGET(label_content_1));
    gtk_widget_show(GTK_WIDGET(label_content_2));
    gtk_widget_show(GTK_WIDGET(tab_label));
    gtk_box_pack_start(GTK_BOX(tab_label), label_content_1, TRUE, TRUE, 0);
    gtk_box_pack_end(GTK_BOX(tab_label), label_content_2, FALSE, FALSE, 0);
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page_content, tab_label);
    gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), TRUE);
    gtk_container_add(GTK_CONTAINER(window), notebook);

    gtk_widget_show_all(GTK_WIDGET(window));

    gtk_main();
}

我无法解释其背后的原因。 您可能会发现此link关于带有关闭按钮的标签很有趣。