GTK+ CellRendererCombo 传递有关 signal_edited 的更多信息
我在 Gtk::TreeView 中创建一个 Gtk::CellRendererCombo,如下所示:
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));
相应的列表存储“m_someListStore”创建为:
{
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...
我的问题是,当我从 CellRenderer Combo 中选择时,它由 SomeClass::onEdited 方法处理。
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 包含我的 CellRendererCombo (someList_str) 中选定的字符串值。有什么方法可以传递 int id (someList_id) 吗?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此页面来自 gtkmm文档展示了如何使用 sigc::bind 模板类将额外参数传递给信号处理程序。
gtkmm 开发人员似乎或多或少对此感到不满,但对我来说(披露:在普通的旧 C 中进行 GTK+ 编程相当长的背景)感觉很自然。并非所有东西都是子类化的小部件。
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.