Re: Using a TreeStore with a ComboBox



Well, if it's really *just* that:


This is what I expected, because in my model all toplevel nodes have children. Of
course this is not the solution I need.

and the grander scheme isn't something bigger, then you can just alter the function to:

bool
Example::on_model_visible (const Gtk:TreeModel::const_iterator& iter)
{
  return (iter != store->children().begin && iter->children().empty());
}



On 6/23/07, Jef Driesen <jefdriesen hotmail com> wrote:
Jonathon Jongsma wrote:
> On 6/22/07, Jef Driesen <jefdriesen hotmail com> wrote:
>> Jonathon Jongsma wrote:
>>> 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.
>> I tried a TreeModelFilter like this:
>>
>> Glib::RefPtr<Gtk::TreeStore> store = Gtk::TreeStore::create(m_columns);
>> Glib::RefPtr<Gtk::TreeModelFilter> filter = Gtk::TreeModelFilter::create
>> (store);
>> filter->set_visible_func (sigc::mem_fun(*this, &Example::on_model_visible
>> combo.set_model(filter);
>>
>> bool
>> Example::on_model_visible (const Gtk:TreeModel::const_iterator& iter)
>> {
>>     return iter->children().empty();
>> }
>>
>> But it doesn't work. Exactly the same tree structure is shown if the
>> model is populated after the set_visible_func. Or the combobox is
>> completely empty, if the tree is populated before that.
>
> does it work if you explicitly call TreeModelFilter::refilter() after
> populating the model?  I'm not sure whether this should be necessary,
> but it might give you a clue as to what's not working...

After refilter, the combobox contains no items anymore, just like when I
populate the model before using set_visible_func. This is what I
expected, because in my model all toplevel nodes have children. Of
course this is not the solution I need.

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list



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