[Lablgtk] GTree.cell_renderer_toggle not activatable by user
pdgroves at gmail.com
Mon Dec 20 02:30:26 CET 2010
For reasons I've never understood, you have to monitor the 'toggled'
events from the cell_renderer and in the monitoring function you have
to 'set' the value in the model to be the opposite of the old value.
Sorry to dump partial code on you, but I don't have time to give you a
good writeup of what happens. Below is the code I have in my app that
does what you're trying to do. This code snippet occurs when I'm
building a GTree.view. Like you, I got it working using guess-and-check
programming (which GTK development requires far too often) so I can't
guarantee you everything in here is really necessary.
(** add the checkbox column to the view *)
let checkBoxModelCol = localModel.checkBoxColumn in
let renderOptionsCheckBox = [(`ACTIVATABLE true); (`ACTIVE true)] in
let rendererCheckBox = GTree.cell_renderer_toggle renderOptionsCheckBox
let toggleMonitor = fun gtkTreePath -> begin
Log.info "toggle monitor firing";
let modelIter = treeModel#get_iter gtkTreePath in
let existingBoolVal = treeModel#get
let newBoolVal = (not existingBoolVal) in
treeModel#set ~row:modelIter ~column:checkBoxModelCol newBoolVal;
ignore (rendererCheckBox#connect#toggled ~callback:toggleMonitor);
let viewColumnCheckBox = GTree.view_column
~renderer:(rendererCheckBox, [("active",checkBoxModelCol)]) ()
On Mon, 20 Dec 2010 01:10:21 +0100
Adrien <camaradetux at gmail.com> wrote:
> I've been trying to get a treeview with checkboxes that the user can
> toggle but they don't "react" in the interface.
> I'm currently using
> let renderer_toggle = GTree.cell_renderer_toggle [ `ACTIVATABLE
> true ] in but in vain.
> I've made a pretty small reproducer (around 30 lines) which I've
> Compile with ocamlfind ocamlopt -linkpkg -package lablgtk2
> cell_renderer_toggle_activatable.ml -o
> I'm not very confortable with treeviews so I may be doing something
> pretty dumb but I really can't see what. Any help is appreciated.
> Thanks. :-)
> Adrien Nader
Lablgtk mailing list
Lablgtk at yquem.inria.fr
More information about the Lablgtk-list