[pygtk] button-press-event on a TreeViewColumn Header?

Tim Evans t.evans at aranz.com
Thu Jun 18 06:36:48 WST 2009


Alessandro Dentella wrote:
> Hi,
> 
>   I'd like to connect to a 'button-press-event' of a column header of a
>   TreeViewColumn. As only clicked is provided, I set the widget::
> 
>         label = gtk.Label(title)
>         box = gtk.EventBox()
>         box.add(label)
>         column.set_widget(box)
>         box.connect('button-press-event', self.box_clicked_cb)
> #        column.connect('clicked', self.clicked_cb)
> 
>   but box_clicked_cb is never called. Why that?
> 
>   Any Hints?

I've used this code as a hack to get the column header button before:

   temp = gtk.Label('Temp')
   column.set_widget(temp)
   button = temp.get_parent().get_parent().get_parent()
   column.set_widget(None)
   temp.destroy()

Now what you have in 'button' is the gtk.Button widget that is used to 
render the column header.  Your button-press-event connection will work 
on that widget, provided you make headers clickable on the treeview:

   treeview.set_headers_clickable(True)

-- 
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/


More information about the pygtk mailing list