Popover

GtkPopover is a bubble-like context window, primarily meant to provide context-dependent information or options. Popovers are attached to a widget, passed at construction time on Popover.new, or updated afterwards through Popover.setRelativeTo, by default they will point to the whole widget area, although this behavior can be changed through Popover.setPointingTo.

The position of a popover relative to the widget it is attached to can also be changed through Popover.setPosition.

By default, gtk.Popover performs a GTK+ grab, in order to ensure input events get redirected to it while it is shown, and also so the popover is dismissed in the expected situations (clicks outside the popover, or the Esc key being pressed). If no such modal behavior is desired on a popover, Popover.setModal may be called on it to tweak its behavior.

GtkPopover as menu replacement

GtkPopover is often used to replace menus. To facilitate this, it supports being populated from a gio.MenuModel, using Popover.newFromModel. In addition to all the regular menu model features, this function supports rendering sections in the model in a more compact form, as a row of icon buttons instead of menu items.

To use this rendering, set the ”display-hint” attribute of the section to ”horizontal-buttons” and set the icons of your items with the ”verb-icon” attribute.

|[ <section> <attribute name="display-hint">horizontal-buttons</attribute> <item> <attribute name="label">Cut</attribute> <attribute name="action">app.cut</attribute> <attribute name="verb-icon">edit-cut-symbolic</attribute> </item> <item> <attribute name="label">Copy</attribute> <attribute name="action">app.copy</attribute> <attribute name="verb-icon">edit-copy-symbolic</attribute> </item> <item> <attribute name="label">Paste</attribute> <attribute name="action">app.paste</attribute> <attribute name="verb-icon">edit-paste-symbolic</attribute> </item> </section>

# CSS nodes

GtkPopover has a single css node called popover. It always gets the
.background style class and it gets the .menu style class if it is
menu-like (e.g. [gtk.PopoverMenu.PopoverMenu|gtk.PopoverMenu] or created using [gtk.Popover.Popover.newFromModel|Popover.newFromModel].

Particular uses of GtkPopover, such as touch selection popups
or magnifiers in [gtk.Entry.Entry|gtk.Entry] or [gtk.TextView.TextView|gtk.TextView] get style classes
like .touch-selection or .magnifier to differentiate from
plain popovers.

Since: 3.12

Constructors

this
this(GtkPopover* gtkPopover, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this(Widget relativeTo)

Creates a new popover to point to relative_to

this
this(Widget relativeTo, MenuModel model)

Creates a gtk.Popover and populates it according to model. The popover is pointed to the relative_to widget.

Members

Functions

addOnClosed
gulong addOnClosed(void delegate(Popover) dlg, ConnectFlags connectFlags)

This signal is emitted when the popover is dismissed either through API or user interaction.

bindModel
void bindModel(MenuModel model, string actionNamespace)

Establishes a binding between a gtk.Popover and a gio.MenuModel

getConstrainTo
GtkPopoverConstraint getConstrainTo()

Returns the constraint for placing this popover. See Popover.setConstrainTo.

getDefaultWidget
Widget getDefaultWidget()

Gets the widget that should be set as the default while the popover is shown.

getModal
bool getModal()

Returns whether the popover is modal, see gtk_popover_set_modal to see the implications of this.

getPointingTo
bool getPointingTo(GdkRectangle rect)

If a rectangle to point to has been set, this function will return TRUE and fill in rect with such rectangle, otherwise it will return FALSE and fill in rect with the attached widget coordinates.

getPopoverStruct
GtkPopover* getPopoverStruct(bool transferOwnership)

Get the main Gtk struct

getPosition
GtkPositionType getPosition()

Returns the preferred position of popover.

getRelativeTo
Widget getRelativeTo()

Returns the widget popover is currently attached to

getStruct
void* getStruct()

the main Gtk struct as a void*

getTransitionsEnabled
bool getTransitionsEnabled()

Returns whether show/hide transitions are enabled on this popover.

popdown
void popdown()

Pops popover down.This is different than a Widget.hide call in that it shows the popover with a transition. If you want to hide the popover without a transition, use Widget.hide.

popup
void popup()

Pops popover up. This is different than a Widget.show call in that it shows the popover with a transition. If you want to show the popover without a transition, use Widget.show.

setConstrainTo
void setConstrainTo(GtkPopoverConstraint constraint)

Sets a constraint for positioning this popover.

setDefaultWidget
void setDefaultWidget(Widget widget)

Sets the widget that should be set as default widget while the popover is shown (see Window.setDefault). gtk.Popover remembers the previous default widget and reestablishes it when the popover is dismissed.

setModal
void setModal(bool modal)

Sets whether popover is modal, a modal popover will grab all input within the toplevel and grab the keyboard focus on it when being displayed. Clicking outside the popover area or pressing Esc will dismiss the popover and ungrab input.

setPointingTo
void setPointingTo(GdkRectangle* rect)

Sets the rectangle that popover will point to, in the coordinate space of the widget popover is attached to, see Popover.setRelativeTo.

setPosition
void setPosition(GtkPositionType position)

Sets the preferred position for popover to appear. If the popover is currently visible, it will be immediately updated.

setRelativeTo
void setRelativeTo(Widget relativeTo)

Sets a new widget to be attached to popover. If popover is visible, the position will be updated.

setTransitionsEnabled
void setTransitionsEnabled(bool transitionsEnabled)

Sets whether show/hide transitions are enabled on this popover

Static functions

getType
GType getType()

Variables

gtkPopover
GtkPopover* gtkPopover;

the main Gtk struct

Inherited Members

From Bin

gtkBin
GtkBin* gtkBin;

the main Gtk struct

getBinStruct
GtkBin* getBinStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getType
GType getType()
getChild
Widget getChild()

Gets the child of the gtk.Bin, or NULL if the bin contains no child widget. The returned widget does not have a reference added, so you do not need to unref it.