gpt4 book ai didi

无法在 TreeView 中切换复选框

转载 作者:行者123 更新时间:2023-12-02 04:52:00 24 4
gpt4 key购买 nike

我有一个简单的对话框,其中包含一个包含 2 列的表格,其中一列是一个复选框。我已经添加了一个 GtkCellRendererToggle 但那个是不可点击的。看来我添加了一个从未调用过的 onToggle 函数。单元格渲染器是可激活的,为了安全起见,我在 C 代码中添加了第二次激活它的调用,但没有任何帮助。我究竟做错了什么?这是代码:

void
on_button_delete_files_click (GtkTreeSelection * widget, gpointer user_data)
{
GtkDialog * dialog = NULL;
GtkWidget * file_choser;
char * msg = NULL;
GtkListStore * liststore = NULL;
GtkTreeIter iter;
GDir * dir = NULL;
char * filename = NULL;

if (!builder_delete_files_dialog) {
GError * error = NULL;
builder_delete_files_dialog = gtk_builder_new ();
if (!gtk_builder_add_from_file (builder_delete_files_dialog, "deletedlg.glade", &error)) {
g_warning ("%s", error->message);
g_free (error);
exit (1);
}
}

//
// Get list store
//
liststore = GTK_LIST_STORE (gtk_builder_get_object (builder_delete_files_dialog, "podcast_file_liststore"));
//gtk_list_store_clear (liststore);

//
// Add all files
//
dir = g_dir_open (download_directory, 0, NULL);
if (NULL == dir) {

}

while (NULL != (filename = g_dir_read_name (dir))) {
if (NULL == g_strrstr (filename, ".mp3"))
continue;

gtk_list_store_append(liststore, &iter);
gtk_list_store_set (liststore, &iter,
TO_BE_DELETED, FALSE,
FILENAME, filename,
-1);
}
//
// nice try since stuff is not activatable
//

GtkCellRendererToggle * toggle = GTK_CELL_RENDERER_TOGGLE(gtk_builder_get_object (builder_delete_files_dialog, "cellrenderertoggle1"));
gtk_cell_renderer_toggle_set_activatable (toggle, TRUE);

dialog = GTK_WIDGET(gtk_builder_get_object (builder_delete_files_dialog, "dialog_delete_files"));

int rc = gtk_dialog_run (GTK_DIALOG(dialog));
switch (rc) {
case GTK_RESPONSE_OK:
case GTK_RESPONSE_CANCEL:
default:
break;
}

gtk_widget_hide (dialog);

__error:
FREE_POINTER(g_dir_close, dir);
}

void on_toggle_renderer_click (GtkCellRendererToggle * cell, char * tree_path, gpointer data)
{
g_print ("=====> Dingens clicked !!! <=====\n");
GtkTreeModel *model = (GtkTreeModel *)data;
GtkTreeIter iter;
GtkTreePath *path = gtk_tree_path_new_from_string (tree_path);
gboolean fixed;

/* get toggled iter */
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, TO_BE_DELETED, &fixed, -1);

/* do something with the value */
fixed ^= 1;

/* set new value */
gtk_list_store_set (GTK_LIST_STORE (model), &iter, TO_BE_DELETED, fixed, -1);

/* clean up */
gtk_tree_path_free (path);
}

这是 XML 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkImage" id="imageApply">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-apply</property>
</object>
<object class="GtkImage" id="imageDelete">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-delete</property>
</object>
<object class="GtkListStore" id="podcast_file_liststore">
<columns>
<!-- column-name TO_BE_DELETED -->
<column type="gboolean"/>
<!-- column-name FILENAME -->
<column type="gchararray"/>
<!-- column-name < -->
<column type="&lt; Neue Spalte definieren &gt;"/>
</columns>
</object>
<object class="GtkDialog" id="dialog_delete_files">
<property name="width_request">320</property>
<property name="height_request">300</property>
<property name="can_focus">False</property>
<property name="resizable">False</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="btnDelete">
<property name="label" translatable="yes">Delete Selected</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">imageDelete</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnClose">
<property name="label" translatable="yes">Close</property>
<property name="name">btnClose</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">imageApply</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="file_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="vexpand">True</property>
<property name="model">podcast_file_liststore</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection2"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<property name="title" translatable="yes">Delete</property>
<child>
<object class="GtkCellRendererToggle" id="cellrenderertoggle1">
<signal name="toggled" handler="on_toggle_renderer_click" object="podcast_file_liststore" swapped="no"/>
</object>
<attributes>
<attribute name="active">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="title" translatable="yes">File name</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-5">btnDelete</action-widget>
<action-widget response="-6">btnClose</action-widget>
</action-widgets>
</object>
</interface>

同样:当我单击复选框时,不会调用 onToggle-Event 处理程序。这让我觉得细胞不知何故不活跃。

非常感谢您的每一个提示。问候凯

最佳答案

我通过将 GtkCellRendererToggle 设置为“可激活”来使其工作 - 即添加值为 True 的“可激活”属性。 – 亚历克斯默里

关于无法在 TreeView 中切换复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27353673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com