从Gtkmm :: Table中删除一行

如何从C ++中的
Gtkmm::Table
中删除一行? 文档真的很差:-(。我尝试过使用
resize()
没有效果,并且在I3ѭ中调用
remove
,我通过
get_children()
获得,但是我得到了段错误...     
已邀请:
如果
Gtkmm::Table
是GtkTable那么gtk_container_remove应该可以做你需要的。我做了一个小例子(见下文),它从表容器中删除了所有标签小部件。
#include <gtk/gtk.h>

void remove_widgets(GtkWidget *widget, gpointer data)
{
    if (GTK_IS_LABEL(widget))
    {
        g_print("remove labeln");
        gtk_container_remove(GTK_CONTAINER(data), widget);
    }
}

void remove_rows(GtkWidget *button, GtkWidget* data)
{
    g_print("remove rows with labelsn");
    gtk_container_foreach(GTK_CONTAINER(data), remove_widgets, data);
}

int main( int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *table;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_widget_set_size_request (window, 300, 250);
    gtk_window_set_resizable(GTK_WINDOW(window), FALSE);

    gtk_window_set_title(GTK_WINDOW(window), "Test Table Remove");

    gtk_container_set_border_width(GTK_CONTAINER(window), 15);

    table = gtk_table_new(3, 2, FALSE);
    gtk_table_set_col_spacings(GTK_TABLE(table), 3);

    GtkWidget *label0 = gtk_label_new("Test Label 0");
    gtk_table_attach(GTK_TABLE(table), label0, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
    GtkWidget *label1 = gtk_label_new("Test Label 1");
    gtk_table_attach(GTK_TABLE(table), label1, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0);

    GtkWidget *label2 = gtk_label_new("Test Label 3");
    gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
    GtkWidget *label3 = gtk_label_new("Test Label 4");
    gtk_table_attach(GTK_TABLE(table), label3, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 0, 0);

    GtkWidget *button0 = gtk_button_new_with_label("Remove Labels");
    gtk_widget_set_size_request(button0, 70, 30);
    gtk_table_attach(GTK_TABLE(table), button0, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0);

    g_signal_connect(G_OBJECT(button0), "clicked", G_CALLBACK(remove_rows), table);

    gtk_container_add(GTK_CONTAINER(window), table);

    g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), G_OBJECT(window));

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}
希望这有帮助,问候     

要回复问题请先登录注册