Re: Obtaining coordinates of a widget



On Wed, 2003-03-19 at 05:48, Daniel Haude wrote:
Hello all,

I'd like to place a largish explanatory popup window next to a
button as soon as the mouse pointer moves over it (sort of like a
tool tip, only immediately and at a well-defined position). My
problem is to get the proper coordinates of the button widget in
order to move the popup window to the appropriate place with
gtk_window_move.

What I've been trying to do is:


static void on_b_thumbnail_enter (GtkButton * button, gpointer
user_data)
{
      int x, y;
      if (!popup) {
              popup = create_wInfo();
      }
      gdk_window_get_root_origin(wBrowser->window, &x, &y);
      x += (GTK_WIDGET(button)->allocation.x
              - GTK_WIDGET(popup)->allocation.width);
      y += GTK_WIDGET(button)->allocation.y;
      gtk_window_move(GTK_WINDOW(popup), x, y);
      gtk_widget_show(popup);
      (void) user_data;
}



but the popup window gets shown at all sorts of weird offsets,
especially since the button widget is placed inside a scrolled
window. All I need to know is where the button is at the time the
mouse pointer enters, but I can't see how. Do I have to dig
through all the nested container widgets to finally arrive at
the position of the button? Any hints?

allocation.x/y are relative to the button's window, so:

 gdk_window_get_origin (button->window);
 
will work better. You can look at the gtkoptionmenu sources.

probably will work better. The other problem you are probably
having is that GTK_WIDGET(popup)->allocation.width isn't
going to hold anything useful until the popup is shown.

Something like:

      gtk_widget_size_request (popup, &requisition);
      width += requisition.width;
 
I*s probably the right thing to do there.

Regards,
                                                Owen





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]