我在 Glade 制作的 gtk-builder 文件中定义了一个窗口。它包含一个, 和一个2 sgtk.Window
的孩子:gtk.TreeView
gtk.TreeViewColumn
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.20"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="bookmarks_window">
<property name="can_focus">False</property>
<property name="events">GDK_KEY_PRESS_MASK | GDK_STRUCTURE_MASK</property>
<property name="title" translatable="yes">Bookmarks</property>
<property name="modal">True</property>
<property name="default_width">350</property>
<property name="default_height">200</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">menu</property>
<property name="skip_taskbar_hint">True</property>
<child>
<object class="GtkScrolledWindow" id="bookmarks_scroll">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<property name="vscrollbar_policy">automatic</property>
<child>
<object class="GtkTreeView" id="bookmarks_tree">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK | GDK_STRUCTURE_MASK</property>
<property name="headers_visible">False</property>
<property name="headers_clickable">False</property>
<property name="rules_hint">True</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">vertical</property>
<child>
<object class="GtkTreeViewColumn" id="line_column">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Line</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="text_column">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Text</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
我正在创建窗口:
def show_window(parent_window):
builder = gtk.Builder()
builder.add_from_file("mywindow.ui")
window = builder.get_object('bookmarks_window')
window.set_transient_for(parent_window)
tree = builder.get_object('bookmarks_tree')
tree.set_search_column(1)
store = gtk.TreeStore(int, str)
for i in xrange(1, 6):
store.append((i, "Line {}".format(i)))
tree.set_model(store)
line_renderer = gtk.CellRendererText()
line_column = builder.get_object('line_column')
line_column.pack_start(line_renderer)
line_column.set_attributes(line_renderer, text=0)
text_renderer = gtk.CellRendererText()
text_column = builder.get_object('text_column')
text_column.pack_start(text_renderer)
text_column.set_attributes(text_renderer, text=1)
window.show_all()
这将只显示“文本”列:
+---------------+
| Line 1 |
| Line 2 |
| Line 3 |
| Line 4 |
| Line 5 |
+---------------+
如果我将gtk.TreeViewColumn
接口文件中 s 的顺序更改为:
<child>
<object class="GtkTreeViewColumn" id="line_column">...</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="text_column">...</object>
</child>
到:
<child>
<object class="GtkTreeViewColumn" id="text_column">...</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="line_column">...</object>
</child>
只有“行”列会显示:
+---------------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+---------------+
但我希望它看起来像:
+---+-----------+
| 1 | Line 1 |
| 2 | Line 2 |
| 3 | Line 3 |
| 4 | Line 4 |
| 5 | Line 5 |
+---+-----------+
更改接口文件中 s 的顺序gtk.TreeViewColumn
正在更改显示的列,这对我来说没有意义。它总是隐藏第一列。有谁知道我错过或忽略了什么?任何帮助,将不胜感激。