GTK+ CellRendererCombo 传递有关 signal_edited 的更多信息

发布于 2024-10-06 16:50:00 字数 1469 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不美如何 2024-10-13 16:50:00

此页面来自 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文