如何在Glade预先创建的列表框中设置listStore模型? [英] How do I set a listStore model on pre-created listbox from Glade?

查看:127
本文介绍了如何在Glade预先创建的列表框中设置listStore模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,在 GTKListBox中包含项目的正确"方式或Treeview 在构造函数中使用listStore模型进行构造.如果我想使用已经在其中创建列表框并由builder.get_object("appsDocumentListBox")引用的列表框的Glade GUI项目怎么办?

Apparently the "proper" way to have items in a GTKListBox or Treeview is constructing with a listStore model, in the constructor. What if I want to use Glade GUI project, in which a list box is already created, and referenced by builder.get_object("appsDocumentListBox")?

我可以在Gtk.builder创建窗口之后设置模型,还是有更好的方法呢?

Can I set the model after Gtk.builder created the window, or is there a better way to do this?

我还想知道与使用row = Gtk.ListBoxRow()手动添加,添加内容并设置ListBox.add(row)相比,使用ListStore可以提高性能吗? (在Glade-builder Python窗口中有效)

I'm also wondering what the performance improvement is of using the ListStore vs manually adding with row = Gtk.ListBoxRow(), adding contents and setting ListBox.add(row)? (which does work from a Glade-builder Python window)

与Treeview不同,显然Listbox不会在构造函数之后设置模型?

Unlike Treeview, apparently Listbox won't set a model after constructor?

>>> l = Gtk.ListBox()
>>> l.set_model
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'ListBox' object has no attribute 'set_model'

推荐答案

您正在混淆两件事.您可以创建一个GtkListBox并向其中添加GtkListBoxRow.这里不需要额外的模型.

You are mixing two things up. You can create a GtkListBox and add GtkListBoxRows to it. There is no need for an extra model here.

还有GtkListStoreGtkTreeStore.他们两个都使用GtkTreeView. ListStore具有平坦的层次结构,并且TreeStore可以嵌套. GtkTreeView具有set_model函数,因此您可以在创建模型后对其进行设置.您也可以直接在Glade中创建相应的模型.

There are also GtkListStore and GtkTreeStore. Both of them use a GtkTreeView. The ListStore has a flat hierarchy and the TreeStore can be nested. The GtkTreeView has a set_model function so you can set a model after you created it. You can also create the corresponding model directly in Glade.

如果您要添加复杂的窗口小部件,则GtkListBox更适合.对于应该被排序或分层结构的大量数据,我宁愿使用GtkTreeView和相应的模型.

If you have complicated widgets that you want to add, the GtkListBox is better suited. For a lot of data which is supposed to be sorted or hierarchically structured, I would rather use a GtkTreeView with a corresponding model.

这篇关于如何在Glade预先创建的列表框中设置listStore模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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