Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gtk

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

Ie, if the widget appears 500 pixels in, and 300 pixels down, but is nested inside various hboxes and tables, how do we find out it is in a 500x300 pixel position?

I need to make a window appear in an exact place under another widget.

thanks

like image 737
user129975 Avatar asked Jan 18 '10 20:01

user129975


2 Answers

Use the gtk_widget_translate_coordinates() function to map from the coordinates of your child widget to the coordinates of the toplevel containing the widget. It might look something like

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

Note that in many cases forcing the position of a new window is a misfeature unless it's acting as a popup menu.

like image 171
Geoff Reedy Avatar answered Oct 28 '22 07:10

Geoff Reedy


Another approach:

gint wx, wy;
gdk_window_get_origin (gtk_widget_get_window (somewidget), &wx, &wy);
like image 39
Ricardo Cruz Avatar answered Oct 28 '22 08:10

Ricardo Cruz