英文:
Get Parent From gtk-rs CompositeTemplate
问题
在impl GnoteTreeView
部分,您可以使用以下代码来获取gtk::TreeView
的引用:
let tree_view: >k::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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论