- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用我找到的代码段将非文本对象保留在 ListStore 中。这些是对象:
class Series(gobject.GObject, object):
def __init__(self, title):
super(Series, self).__init__()
self.title = title
gobject.type_register(Series)
class SeriesListStore(gtk.ListStore):
def __init__(self):
super(SeriesListStore, self).__init__(Series)
self._col_types = [Series]
def get_n_columns(self):
return len(self._col_types)
def get_column_type(self, index):
return self._col_types[index]
def get_value(self, iter, column):
obj = gtk.ListStore.get_value(self, iter, 0)
return obj
现在我试图让 TreeView 显示它:
...
liststore = SeriesListStore()
liststore.clear()
for title in full_conf['featuring']:
series = Series(title)
liststore.append([series])
def get_series_title(column, cell, model, iter):
cell.set_property('text', liststore.get_value(iter, column).title)
return
selected = builder.get_object("trvMain")
selected.set_model(liststore)
col = gtk.TreeViewColumn(_("Series title"))
cell = gtk.CellRendererText()
col.set_cell_data_func(cell, get_series_title)
col.pack_start(cell)
col.add_attribute(cell, "text", 0)
selected.append_column(col)
...
但它失败并出现错误:
GtkWarning: gtk_tree_view_column_cell_layout_set_cell_data_func: assertion
info != NULL' failed<br/>
text' of type
col.set_cell_data_func(cell,
get_series_title)
Warning: unable to set propertygchararray' from value of
data+TrayIcon+Series'
type
window.show_all() Warning: unable to set propertytext'
gchararray' from value of type `data+TrayIcon+Series'
of type
gtk.main()gtk.main()
我应该怎么做才能让它发挥作用?
最佳答案
倒数第二 block 中的两个错误。
GtkWarning: gtk_tree_view_column_cell_layout_set_cell_data_func: assertion `info != NULL'
在英语中,这意味着单元格渲染器不在列的单元格渲染器列表中。在调用 set_cell_data_func
之前,您需要先将单元格渲染器添加到列中。
Warning: unable to set property `text' of type `gchararray' from value of `typedata+TrayIcon+Series'
这是因为 add_attribute
行导致 GTK+ 尝试将单元格文本设置为 Series 对象,这当然会失败。只需删除该行;单元格数据函数已经负责设置单元格文本。
在代码中:
col = gtk.TreeViewColumn(_("Series title"))
cell = gtk.CellRendererText()
col.pack_start(cell)
col.set_cell_data_func(cell, get_series_title)
关于python - 如何让 GtkListStore 连续存储对象属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3488285/
我已经包含了一小段代码。我正在制作一个包含 5 列的 TreeView 。我在最后一列中粘贴了生成要存储在 GtkListStore 中的数据的 for 循环。我可以轻松地将 TreeView 的列居
我正在用 C 编写程序并使用 Gtk+ 作为 GUI。一切正常,但我对可能的内存泄漏有些怀疑。 我需要显示一个元素列表,然后通过搜索栏和按钮过滤这个列表。我想将 GtkTreeView 与 GtkLi
我正在尝试使用我找到的代码段将非文本对象保留在 ListStore 中。这些是对象: class Series(gobject.GObject, object): def __init__(self
我尝试将 GTKButton 添加到 GtkListStore 来编辑每行中的数据...该按钮没有出现,并且我收到此错误消息:“GLib-GObject-WARNING **:无法设置属性 text'
我可以在 GtkListStore 中存储未指定的类型吗?比如我想存储在一个字段中——int类型的字段和GdkColor类型的字段? 最佳答案 我想你的意思是unions in C C++ 关于c++
我正在尝试将 GSList 传递给 GtkListStore 以显示给用户。但是当我将值设置为 GtkListStore 时,它只会给我段错误。我真的不知道问题出在哪里。我测试了列表,所以它不是空
我在 Glade 中创建了一个带有 TreeView 的 GUI。这是 XML 文件: False
如何连接 GtkTreeVew 和 GtkListStore? 我的 TreeView 可以很好地显示 ListStore 的数据,但当用户更改其中一个 cellrenderer 小部件中的值时,不会
您好,我使用glade 编写了一个小型gtk 应用程序。 该应用程序包括一个列表存储。每当用户单击一行时,我都希望能够获取该行包含的信息。 在 row-changed 事件下使用 Glade 我添加了
我想要一个用于 GtkListStore 的带有文本的按钮。我使用图像作为按钮阅读了另一个答案,但我确实需要标题为文本。我怎样才能做到这一点?我也可以使用将文本呈现到 GdkPixbuf 上的解决方案
我正在开发一个小型 PyGtk 项目,该项目使用 GtkListStore 来包含我想在 GtkIconView 中显示为图标的元素数据。我正在使用 Glade 设计 UI。 我知道如何以编程方式将数
我正在使用这段代码创建一个带有彩色背景/文本的组合框: GtkListStore *liststore; GtkWidget *combo; GtkCellRenderer *column; list
我试图在 Gtk.TreeView 的不同列上显示对象的属性.说我有以下几点: class MyClass(GObject.GObject): def __init__(self, first
我一直在自学如何用 C 编写代码并利用 GTK 在 Linux 中编写应用程序,在实现它之前使用 Glade 设计 UI。我一直在尝试结合使用 GtkTreeView 和 GtkListStore 来
我用 C 语言将一个程序移植到 GTK3,除了一件事之外,一切都很完美。假设 TreeView 一次只显示 10 行,但填充了 100 行,其他行当然不在 View 中, TreeView 设置为单选
我是一名优秀的程序员,十分优秀!