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

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

Get Parent From gtk-rs CompositeTemplate

问题

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

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

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

英文:

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

    #[derive(Debug, Default, gtk::CompositeTemplate)]
    #[template(resource = "/org/bil4x4/gnote/tree_view")]
    pub struct GnoteTreeView {
        #[template_child]
        pub tree_store: TemplateChild<gtk::TreeStore>,

        pub add_note_visible: Cell<bool>,
        pub add_folder_visible: Cell<bool>,
        pub remove_item_visible: Cell<bool>,
    }

    #[glib::object_subclass]
    impl ObjectSubclass for GnoteTreeView {
        const NAME: &'static str = "GnoteTreeView";
        type Type = super::GnoteTreeView;
        type ParentType = gtk::TreeView;

        fn class_init(klass: &mut Self::Class) {

            klass.bind_template();
            klass.bind_template_instance_callbacks();
        }

        fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
            obj.init_template();
        }
    

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

答案是使用:

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

The answer is to use

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:

确定