Re: Using a TreeStore with a ComboBox



Andrew E. Makeev wrote:
В Чтв, 21/06/2007 в 10:53 -0500, Jonathon Jongsma пишет:
On 6/21/07, Jef Driesen <jefdriesen hotmail com> wrote:
Using a treestore model with a combobox creates a nice dropdown list
with submenus. Inside each submenu, the parent item is shown with a
separator below to separate it from its children. I want to know how I
can hide this parent node, so I can only select leaf nodes (e.g items
without children).

The model contains places that can be are arranged by the user in an
arbitrary hierarchy, to group related places together (for instance by
continent and/or country). This is very similar how files (my places)
can be arranged into directories (my hierarchy). But when the user needs
to select a place with the combobox, it doesn't make sense to be able to
select an item that is not a place.
You could probably accomplish this fairly easily with TreeModelFilter
(http://gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1TreeModelFilter.html)
wrapping your existing treestore. You'd just need to provide a
function which checks whether a node has children or not, and pass
that function to TreeModelFilter::set_visible_func().  Hope that
helps.

No, TreeFilterModel wouldn't work in way you need that.

I found this in some tutor for GTK(MM).
Use set_select_function for selection object of your TreeView.
In that function you should check if you select leaf node and return
true or false.

...
    selectionObject = view.get_selection();
    selectionObject->set_mode( Gtk::SELECTION_SINGLE );

    selectionObject->set_select_function( sigc::mem_fun( *this, &EnvList::check_select ) );
...

bool EnvList::check_select
   (const Glib::RefPtr<Gtk::TreeModel>& model,
    const Gtk::TreeModel::Path& path, bool)
{
    const Gtk::TreeModel::iterator iter = model->get_iter (path);
    return iter->children ().empty (); // only allow leaf nodes to be selected
}

This stuff only exists for a treeview, not for a combobox.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]