2012/12/31 Александер Пономарёв <[email protected]>
> Hi all,
> please, tell me somebody, is possible in the vala to get access to one
> widget trough another one?
> To be clear: I have a box and one label on it:
>
> var box = new Box(...);
> var label = new Label(...);
> box.pack_start(label, ...);
>
> and now I have to get access to this label using the box:
>
> box.label.get_text() // or something like that.
>
> Or more clear:
>
> public void set_box(Box box) {
> string label_title = "Hello, Vala!";
> box.label.set_text(label_title);
> }
>
> How can I solve this?
>
Hi.
To answer your question:
Gtk.Box is a Gtk.Container, which implements the function "get_children()"
(returning a List<weak Gtk.Widget>),
so you should do something like
Label label = box.get_children().data as Label; // (not tested)
to retrieve it. This of course only works if the label is the first widget
in the box.
However, I would highly recommend you to keep a separate reference to the
label,
maybe create a subclass of Box and store the label reference in a private
field?
It's hard to give better advice without knowing what exactly you're trying
to achieve though.
_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list