iconspygtkgtktreeview

PyGtk3 - Creating a Gtk.TreeView column header with an icon?


I've got a Gtk.ListStore(int, str) set to a Gtk.Treeview. From this Gtk.ListStore, I just display the str that represents the name of store items.

# Create store and set it to the model
self.__treeview_store = Gtk.ListStore(int, str)  # (Sample_ID, Sample_Name)
self.__w_treeview.set_model(self.__treeview_store)
# Render column name
self.__w_samples_renderer_text = Gtk.CellRendererText()      
self.__w_samples_column = Gtk.TreeViewColumn("Muestras", self.__w_samples_renderer_text, text=1)
self.__w_treeview.append_column(self.__w_samples_column)
# Sort by name
self.__w_samples_column.set_sort_column_id(1)

I don't want to store any Pixbufs in my store. I'm trying to add an icon next to the column header like in the following image:

enter image description here

I've managed to achieve the following, but it's not working as I want yet. I'll keep this updated.

enter image description here


Solution

  • enter image description here

    What I've done is create a horizontal Gtk.Box that contains a Gtk.Label and a Gtk.Button. I've placed this Box above the Gtk.TreeView. I've done this with Glade. You also should hide the columns of your Gtk.TreeView with Gtk.TreeView.set_headers_visible(False) so you only have your Widget as column.

        # [2] The TreeView column 
        self.__w_treeview.set_headers_visible(False) 
        self.__w_samples_renderer_text = Gtk.CellRendererText()
        self.__w_samples_column = Gtk.TreeViewColumn("", self.__w_samples_renderer_text, text=1)
        self.__w_samples_column.set_sort_column_id(1)   
        self.__w_treeview.append_column(self.__w_samples_column)