Re: [Vala] Widgets hierarchy, or how get label on the bix?
- From: Jonas Kulla <nyocurio gmail com>
- To: vala-list <vala-list gnome org>
- Subject: Re: [Vala] Widgets hierarchy, or how get label on the bix?
- Date: Mon, 31 Dec 2012 15:49:50 +0100
2012/12/31 Александер Пономарёв <shootnix gmail com>
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.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]