Marvin Ahlgrimm
Marvin Ahlgrimm

Reputation: 97

Show Gtk.Popover at cursor of Gtk.Entry

I want to to show a Gtk.Popover at the position of the cursor of a Gtk.Entry. I'm only only able to add the popover relative to the entry itself, but the Gtk.Popover appears at the center of the Gtk.Entry everytime.

Is there a way how I can get the position of my Gtk.Entry cursor and create the popover at this position?

Upvotes: 1

Views: 486

Answers (1)

ebassi
ebassi

Reputation: 8805

You should set the widget to which your popover is relative to, by using Gtk.Popover.relative_to; then you can use Gtk.Popover.pointing_to and the rectangle with the location of the cursor. To get that, use Gtk.Entry.cursor_position to retrieve the index of the cursor in characters and transform it into a location within the Pango.Layout of the Gtk.Entry widget; if the entry is allowed to scroll, you should also get the Gtk.Entry.scroll_offset and subtract it from the coordinates returned by Pango.

Upvotes: 3

Related Questions