CellRendererButton: Have a clickable button in a TreeView column

I’ve been trying to put a clickable button in a TreeView (column).

If you want more context, I’m trying to solve issue (https://github.com/pychess/pychess/issues/1688), which requires adding a per-row reset button. It uses gtk3 inPython.

The best I’ve been able to do so far is to have a CellRendererPixbuf in the column, possibly followed by some text.

Thank you for your time ; )

At least you can put a clickable checkmark button in a cell, I did it in http://ssalewski.de/PetEd.html.en, but can not remember how I did it, maybe it was explained in the book of A.Krause.

Google suggests us https://stackoverflow.com/questions/43050975/adding-gtkbutton-to-gtkliststore-with-text-in-gtk – maybe the suggested solution with “put a button below/outside the” is OK for you?

Maybe other people can give you a better answer later.

TreeView columns are made of cell renderers, and cell renderers are not widgets by design—and only widgets can deal with events like button press/release, and enter/leave events. So, the short answer is: you cannot put a GtkButton into a GtkTreeView.

What you can do is put an icon into a cell renderer, and then hack around a bit by connecting to the motion notification event on the tree view widget itself, and every time the pointer moves within it, you can check whether the pointer is on the “button” part of the column, and if so update the icon to emulate the “hover” state. This only works for simple, icon only buttons.

Looking at the issue you linked, I’d recommend moving away from a GtkTreeView widget, and use a GtkListBox widget instead, unless you plan on displaying 100s of rows.

It’s good to have that set clear.

That’s actually what I’ve been able to achieved so far.

That’s very interesting, I wasn’t aware of this option at all. It definitely seems to be an appropriate way to address the problem.

Thank you.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.