从Gtk::TreeStore中删除图像的时髦方法

Tidy way to delete image from Gtk::TreeStore

本文关键字:图像 方法 删除 Gtk TreeStore      更新时间:2023-10-16

我有一个带有Gtk::TreeView的对话框窗口。此对话框显示主文件系统树并提供选择磁盘上文件夹的选项。当用户选择某个文件夹时,我将Gtk::Stock图像添加到表示该文件夹的行中。

为此,我创建了一个Gtk::CellRendererPixbuf,它与树的最后一列相关联

//appending columns
directory_tree.append_column("Folder List", dir_columns.name);
Gtk::TreeViewColumn *column = directory_tree.get_column(0);
if(column) column->set_expand(true);
Gtk::CellRendererPixbuf *cell = Gtk::manage(new Gtk::CellRendererPixbuf);
directory_tree.append_column("", *cell);
column = directory_tree.get_column(1);
if(column) column->add_attribute(cell->property_stock_id(), dir_columns.stock_id);

链接到此代码位:https://github.com/mc-suchecki/Imagine/blob/master/gui/dialogs.cpp#L47

在"dir_columns.stock_id"中找到Gtk::CellRendererPixbuf"translates"到位于树中的图像。当我像这样将图像添加到行中时:

//selecting folder
(*folder)[fs_columns.stock_id] = Gtk::StockID(Gtk::Stock::FIND).get_string();
(*folder)[fs_columns.included] = true;

一切都还好,但当我尝试以这种方式删除图像时:

//unselecting folder
(*folder)[fs_columns.stock_id] = "";
(*folder)[fs_columns.included] = false;

图像正确地消失了,但命令行中有一些错误,如下所示(这不是确切的消息,我将在能够启动我的应用程序时发布它):

(imagine:9376): Gtk-WARNING **: Gtk StockId not found 

当然,发出警告的原因是显而易见的(没有与空白名称关联的StockId项),但我的问题是:有没有办法从Gtk::TreeView行中删除不会生成任何Gtk警告的图像?

我取消选择文件夹的代码在这里:https://github.com/mc-suchecki/Imagine/blob/master/core/core.cpp#L207

事先非常感谢你,对我的英语感到抱歉。

如果要删除图像,请将visible属性更改为false,而不是stock-id属性。