我在用Glade创建的gtk-builder文件中定义了一个窗口。它包含gtk.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
如果我改变了接口文件中<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 |
+---------------+
仅显示“Line”列:
+---+-----------+
| 1 | Line 1 |
| 2 | Line 2 |
| 3 | Line 3 |
| 4 | Line 4 |
| 5 | Line 5 |
+---+-----------+
但我希望它看起来像:
gtk.TreeViewColumn
更改接口文件中{{1}}的顺序正在改变显示的列,这对我来说没有意义。它总是隐藏第一列。有谁知道我错过或忽视了什么?任何帮助将不胜感激。
答案 0 :(得分:1)
您将列大小调整模式设置为“fixed”(我假设您出于性能原因需要这个),但不设置fixed-width
属性。将它设置为两列上的任何值,它们将出现。