从gtk-rs的CompositeTemplate中获取父组件

huangapple go评论94阅读模式
英文:

Get Parent From gtk-rs CompositeTemplate

问题

impl GnoteTreeView部分,您可以使用以下代码来获取gtk::TreeView的引用:

  1. let tree_view: &gtk::TreeView = self.upcast_ref();

这将从CompositeTemplate的父类型中获取gtk::TreeView的引用。

英文:

How do I get the parent of a CompositeTemplate in gtk-rs?

  1. #[derive(Debug, Default, gtk::CompositeTemplate)]
  2. #[template(resource = "/org/bil4x4/gnote/tree_view")]
  3. pub struct GnoteTreeView {
  4. #[template_child]
  5. pub tree_store: TemplateChild<gtk::TreeStore>,
  6. pub add_note_visible: Cell<bool>,
  7. pub add_folder_visible: Cell<bool>,
  8. pub remove_item_visible: Cell<bool>,
  9. }
  10. #[glib::object_subclass]
  11. impl ObjectSubclass for GnoteTreeView {
  12. const NAME: &'static str = "GnoteTreeView";
  13. type Type = super::GnoteTreeView;
  14. type ParentType = gtk::TreeView;
  15. fn class_init(klass: &mut Self::Class) {
  16. klass.bind_template();
  17. klass.bind_template_instance_callbacks();
  18. }
  19. fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
  20. obj.init_template();
  21. }

so in the impl GnoteTreeView section I am not sure how to get the gtk::TreeView. I am pretty sure it is something like self.imp().?

I have tried looking in self.imp().? and I am expecting to get a reference to the gtk::TreeView from the CompositeTemplate parent.

答案1

得分: 0

答案是使用:

  1. self.imp().instance()
英文:

The answer is to use

  1. self.imp().instance()

huangapple
  • 本文由 发表于 2023年5月11日 11:36:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223993.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定