tags:

views:

47

answers:

1

I need to retrieve the position of a Gtk::Widget relative to its parent, a Gtk::Table. Most sources (e.g. http://library.gnome.org/devel/gtk-faq/stable/x642.html) say that one needs to call Gtk::Widget::get_allocation(). However, the returned Gtk::Allocation object always contains x = -1, y = -1, width = 1, height = 1.

I have to note that this happens before the Gtk::Table object is actually exposed and rendered. A call to show_all_children() or check_resize(), which I would expect to recalculate child widget geometry, doesn't help.

What am I doing wrong? Thanks in advance.

A: 

You could try calling gtk_widget_realize() on the top-level GtkTable.

Another approach, as suggested in the documentation I linked, is to attach a handler to the GtkWidget::expose-event signal.

unwind
Thanks, but it doesn't work. Besides, `Gtk::Widget::realize()` is class-protected in the C++ API. So I guess I will have to delay the work until the `expose` event is delivered.
a-v