1

我想要一个带有文本的按钮GtkListStore。我使用图像作为按钮阅读了另一个答案,但我真的需要标题是文本。我怎样才能做到这一点?我也可以使用将文本呈现到 a 上的解决方案GdkPixbuf

我试过这个:

GType *types;

types = g_new0 (GType, num_fields);

for(int i=0; i<num_fields; i++) {
    types[i] = GTK_TYPE_BUTTON;
}

tree_store = gtk_list_store_newv(num_fields, types);
tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store));

GtkTreeViewColumn *column;
    GtkCellRenderer *renderer;
    GdkPixbuf     *icon;
    renderer = gtk_cell_renderer_pixbuf_new();
    column = gtk_tree_view_column_new_with_attributes (name.c_str(),renderer,"pixbuf",i,NULL);

button = gtk_button_new_with_label ("Quit");
        g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
        gtk_widget_set_can_default (button, TRUE);
        gtk_list_store_set(tree_store, &iter, j, button, -1);

没有错误,但没有任何显示。

我想在新窗口中查看选择。

4

1 回答 1

0

你有两个选择(实际上你有两个以上的选择,但在我继续之前你需要尝试前两个)。

连接到树视图“row_activated”信号,可以设置为单击或双击。这将传递到所选行的路径。

Put a button below/outside the treeview that gets a treeview "get_selected_row". You can then use this to get the content of the row you wish to open in a new window. Example. Hint: this is how Gtk recommends using buttons with a treeview.

于 2017-05-02T02:25:17.887 回答