使用GTK +中的文本将GtkButton添加到GtkListStore [英] Adding GtkButton to GtkListStore with text in GTK+

查看:150
本文介绍了使用GTK +中的文本将GtkButton添加到GtkListStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want a button with text on it for a GtkListStore. I read another answer using an image as a button, but I really need the title to be text. How can I do this? I'd be fine with a solution that renders text onto a GdkPixbuf as well.

我已经尝试过了:

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);

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

There are no errors, but nothing shows up.

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

I want to view the selection in a new window.

推荐答案

您有两个选择(实际上,您有两个以上的选择,但是在继续之前,您需要尝试前两个).

You have two options (actually you have more than two options, but you need to try the first two before I continue).

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

Hook up to the treeview "row_activated" signal, which can be set to single or double click. This will pass in the path to the selected row.

在树视图下方/外部放置一个按钮,以获取树视图"get_selected_row".然后,您可以使用它在新窗口中获取要打开的行的内容. 示例.提示:这是Gtk建议使用带有树状视图的按钮的方式.

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.

这篇关于使用GTK +中的文本将GtkButton添加到GtkListStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆