I have a problem with Gtk.Treeview
indide a Gtk.ScrolledWindow
. I have a large amount of data, which doesnt fit inside my normal window geometrics, so i put my Treeview inside a ScrolledWindow
, which seems to be the normal way. The problem with this solution is, that my Column Headers disapear, when I scroll. This behaviour seems somewhat ok to me, since the ScrolledWindow
should care about the widgets inside of it.
So, how do I get my Treeview to be scrollable AND show the column headers always in the first row?
I modified the basictreeview.py example to represent my problem:
#!/usr/bin/env python
# example basictreeview.py
import pygtk
pygtk.require('2.0')
import gtk
class BasicTreeViewExample:
# close the window and quit
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def __init__(self):
# Create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("Basic TreeView Example")
self.window.set_size_request(200, 200)
self.window.connect("delete_event", self.delete_event)
# create a TreeStore with one string column to use as the model
self.liststore = gtk.ListStore(str)
# we'll add some data now - 4 rows with 3 child rows each
for i in range(10):
self.liststore.append([str(i)])
# create the TreeView using treestore
self.treeview = gtk.TreeView(self.liststore)
# create the TreeViewColumn to display the data
self.tvcolumn = gtk.TreeViewColumn("Column-Name", gtk.CellRendererText(), text=0)
# add tvcolumn to treeview
self.treeview.append_column(self.tvcolumn)
# make it searchable
self.treeview.set_search_column(0)
# Allow sorting on the column
self.tvcolumn.set_sort_column_id(0)
# Allow drag and drop reordering of rows
self.treeview.set_reorderable(True)
# Add Treeview to a ScrolledWindow
self.scrolledwindow = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)
self.scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.scrolledwindow.add_with_viewport(self.treeview)
self.window.add(self.scrolledwindow)
self.window.show_all()
def main():
gtk.main()
if __name__ == "__main__":
tvexample = BasicTreeViewExample()
main()