viraptor
viraptor

Reputation: 34145

How to catch clicks in a Gtk.TreeView?

I'm trying to catch a double-click event in a TreeView's empty area to create a new node. Unfortunately standard way doesn't work. I've tried attaching ButtonPressEvent to both TreeView and the ScrolledWindow in which T.V. is hosted. I don't get any callbacks to my function.

How can I solve this?

Upvotes: 4

Views: 3908

Answers (3)

city
city

Reputation: 21

http://old.nabble.com/CellRenderer-editable-on-double-click-td24975510.html

self.treeview.connect("button-press-event",self.cell_clicked)

def cell_clicked(self, widget, event):
     if event.button == 1 and event.type == gtk.gdk.BUTTON_PRESS:
        print "Double clicked on cell"

Upvotes: 2

anthony
anthony

Reputation: 41088

You'll need to use the GLib.ConnectBeforeAttribute on your handler to handle TreeView.ButtonPressEvent, otherwise the widget will handle the event internally and your handler won't be called.

example:

[GLib.ConnectBefore]
void OnTreeViewButtonPressEvent(object sender, ButtonPressEventArgs e)
{
    if (e.Type == Gdk.EventType.TwoButtonPress)
    {
        // double click
    }
}    

Upvotes: 8

Sujay Ghosh
Sujay Ghosh

Reputation: 2868

I think the Treeview has a window of its own.

Get the window handle, and then SendMessage(treeview->Getsafehwnd() , tvi_root, tvichildren)

The above send message is for your understanding only .

Upvotes: -4

Related Questions