开发者

Retrieving Gtk::Widget's relative position: get_allocation() doesn't work

开发者 https://www.devze.com 2022-12-23 21:28 出处:网络
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::Widge

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开发者_如何学Python, 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消