How do you find the absolute position of a GTK widget in a window?

I can use the highlight function "GTK", but this only gives a position relative to its parent. How to find the absolute position of a GTK widget inside a window?

That is, if a widget appears with 500 pixels in inches and 300 pixels down, but is nested inside different hboxes and tables, how do we find out that it is at a pixel position of 500x300?

I need the window to appear in the exact location under another widget.

thanks

+7
gtk
source share
2 answers

Use the gtk_widget_translate_coordinates() function to map the coordinates of the coordinates of the child widget to the coordinates of the top level containing the widget. It might look something like this:

 GtkWidget *somewidget; gint wx, wy; gtk_widget_translate_coordinates(somewidget, gtk_widget_get_toplevel(somewidget), 0, 0, &wx, &wy); 

Please note that in many cases, forcing the position of a new window is unreliable if it does not act as a pop-up menu.

+12
source share

Another approach:

 gint wx, wy; gdk_window_get_origin (gtk_widget_get_window (somewidget), &wx, &wy); 
+4
source share

All Articles