开发者

GTK+ CellRendererCombo Pass More Info on signal_edited

I create a Gtk::CellRendererCombo in a Gtk::TreeView like so:

Gtk::CellRendererCombo *someRenderer = manage(new Gtk::CellRendererCombo());
someRenderer->property_has_entry() = false;
someRenderer->property_text_column() = 0;
someRenderer->property_editable() = true;
someRenderer->property_model() = m_someListStore;
someRenderer->signal_edited().connect(sigc::mem_fun(*this, &SomeClass::onEdited));
col = manage(new Gtk::TreeViewColumn(_("Some Column Name"),*someRenderer));

Where the corresponding list store "m_someListStore" is created as:

{
Gtk::TreeModel::ColumnRecord colRec;
colRec.add(someList_str);
colRec.add(someList_id);
m_someListStore = Gtk::ListStore::create(colRec);
}

Gtk::TreeModel::iterator itr1 = m_someListStore->append();
(*itr1)[lotInfoCol_id] = 0;
(*itr1)[lotInfoCol_str] = "Zero";
itr1 = m_someListStore->append();
(*itr1)[lotInfoCol_id] = 1;
(*itr1)[lotInfoCol_str] = "One";
etc...

My problem is when I select from the CellRenderer Combo it get's handled by the SomeClass::onEdited method.

void SomeClass::onEdited(const Glib::ustring& path_string, const Glib::ustring& new_text)
{
  Gtk::TreePath path(path_string);
  Gtk::开发者_开发问答TreeModel::iterator iter = m_TreeViewListStore->get_iter(path);
  if(iter)
  {
    Gtk::TreeRow row = *iter;
    row[m_TreeViewModel.some_column] = new_text;
  }
}

new_text contains the selected string value in my CellRendererCombo (someList_str). Is there any way I can also pass in the int id (someList_id)?

Thanks.


This page from the gtkmm documentation shows how to use the sigc::bind<> template class to pass extra parameters to the signal handler.

It seems to be more or less frowned-upon by the gtkmm developers, but for me (disclosure: with a rather long background programming GTK+ in plain old C) it feels quite natural. Not everything is a subclassed widget.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜