我想滚动Gtk.TreeView
的内容。这意味着行而不是标题。所以使用Gtk.ScrolledWindow
在这里没有用,因为这会滚动完整的小部件。
我找到Gtk.Adjustment
但不知道如何使用它。
这是我到目前为止所尝试的
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class TreeView(Gtk.TreeView):
def __init__(self):
# model
self.model = Gtk.ListStore.new([int])
for i in range(30):
self.model.append([i])
# view
Gtk.TreeView.__init__(self, self.model)
col_a = Gtk.TreeViewColumn('int',
Gtk.CellRendererText(),
text=0)
self.append_column(col_a)
# "adjustment" ???
self.adj = Gtk.Adjustment()
self.set_vadjustment(self.adj)
class Window(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title='Mein Gtk-Fenster')
self.set_default_size(100, 120)
self.view = TreeView()
# layout
self.layout = Gtk.Grid()
self.add(self.layout)
self.layout.attach(self.view, 0, 1, 1, 1)
self.connect('destroy', Gtk.main_quit)
self.show_all()
if __name__ == '__main__':
win = Window()
Gtk.main()
答案 0 :(得分:1)
您应该将Gtk.ScrolledWindow
打包到class Window(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title='Mein Gtk-Fenster')
self.set_default_size(100, 120)
self.view = TreeView()
scroll = Gtk.ScrolledWindow () # 1
scroll.add (self.view) # 2
scroll.set_policy (Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
self.add (scroll)
self.connect('destroy', Gtk.main_quit)
self.show_all()
{{1}}
TreeView非常智能,只能滚动内容: