1.148 <GtkPopover>

Class: <GtkPopover>

It derives from <GtkWidget>.

Presents a bubble-like popup.

It is primarily meant to provide context-dependent information or options. Popovers are attached to a parent widget. The parent widget must support popover children, as <GtkMenuButton> and <GtkPopoverMenuBar> do. If you want to make a custom widget that has an attached popover, you need to call popover:present in your widget:do-size-allocate vfunc, in order to update the positioning of the popover.

The position of a popover relative to the widget it is attached to can also be changed with popover:set-position. By default, it points to the whole widget area, but it can be made to point to a specific area using popover:set-pointing-to.

By default, <GtkPopover> performs a 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 Escape key being pressed). If no such modal behavior is desired on a popover, popover:set-autohide may be called on it to tweak its behavior.

GtkPopover as menu replacement

<GtkPopover> is often used to replace menus. The best way to do this is to use the <GtkPopoverMenu> subclass which supports being populated from a <GMenuModel> with popover-menu:new-from-model.

<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>

Shortcuts and Gestures

<GtkPopover> supports the following keyboard shortcuts:

  • Escape closes the popover.
  • Alt makes the mnemonics visible.

The following signals have default keybindings:

CSS nodes

popover.background[.menu]
├── arrow
╰── contents
    ╰── <child>

<GtkPopover> has a main node with name popover, an arrow with name arrow, and another node for the content named contents. The popover node always gets the .background style class. It also gets the .menu style class if the popover is menu-like, e.g. is a <GtkPopoverMenu>.

Particular uses of <GtkPopover>, such as touch selection popups or magnifiers in <GtkEntry> or <GtkTextView> get style classes like .touch-selection or .magnifier to differentiate from plain popovers.

When styling a popover directly, the popover node should usually not have any background. The visible part of the popover can have a shadow. To specify it in CSS, set the box-shadow of the contents node.

Note that, in order to accomplish appropriate arrow visuals, <GtkPopover> uses custom drawing for the arrow node. This makes it possible for the arrow to change its shape dynamically, but it also limits the possibilities of styling it using CSS. In particular, the arrow gets drawn over the content node’s border and shadow, so they look like one shape, which means that the border width of the content node and the arrow node should be the same. The arrow also does not support any border shape other than solid, no border-radius, only one border width (border-bottom-width is used) and no box-shadow.

Fields

parent

Properties

Property: popover:autohide self

Whether to dismiss the popover on outside clicks.

Its value is a boolean.

Set it with (set! (popover:autohide self) value).

Property: popover:cascade-popdown self

Whether the popover pops down after a child popover.

This is used to implement the expected behavior of submenus.

Its value is a boolean.

Set it with (set! (popover:cascade-popdown self) value).

Property: popover:child self

The child widget.

Its value is a <GtkWidget>, or #f.

Set it with (set! (popover:child self) value).

Property: popover:default-widget self

The default widget inside the popover.

Its value is a <GtkWidget>, or #f.

Set it with (set! (popover:default-widget self) value).

Property: popover:has-arrow self

Whether to draw an arrow.

Its value is a boolean.

Set it with (set! (popover:has-arrow self) value).

Property: popover:mnemonics-visible self

Whether mnemonics are currently visible in this popover.

Its value is a boolean.

Set it with (set! (popover:mnemonics-visible self) value).

Property: popover:pointing-to self

Rectangle in the parent widget that the popover points to.

Its value is a <GdkRectangle>, or #f.

Set it with (set! (popover:pointing-to self) value).

Property: popover:position self

How to place the popover, relative to its parent.

Its value is a <GtkPositionType> (or, to set it, one of its symbols).

Set it with (set! (popover:position self) value).

Procedures

Method: popover:get-autohide? self ⇒ %return
Method: get-autohide? self ⇒ %return

Returns whether the popover is modal.

See popover:set-autohide for the implications of this.

self

Passed: a <GtkPopover>.

a <GtkPopover>

%return

Returned: a boolean.

#t if self is modal

Method: popover:get-cascade-popdown? self ⇒ %return
Method: get-cascade-popdown? self ⇒ %return

Returns whether the popover will close after a modal child is closed.

self

Passed: a <GtkPopover>.

a <GtkPopover>

%return

Returned: a boolean.

#t if self will close after a modal child.

Method: popover:get-child self ⇒ %return
Method: get-child self ⇒ %return

Gets the child widget of self.

self

Passed: a <GtkPopover>.

a <GtkPopover>

%return

Returned: a <GtkWidget>, or #f.

the child widget of self

Method: popover:get-has-arrow? self ⇒ %return
Method: get-has-arrow? self ⇒ %return

Gets whether this popover is showing an arrow pointing at the widget that it is relative to.

self

Passed: a <GtkPopover>.

a <GtkPopover>

%return

Returned: a boolean.

whether the popover has an arrow

Method: popover:get-mnemonics-visible? self ⇒ %return
Method: get-mnemonics-visible? self ⇒ %return

Gets whether mnemonics are visible.

self

Passed: a <GtkPopover>.

a <GtkPopover>

%return

Returned: a boolean.

#t if mnemonics are supposed to be visible in this popover

Method: popover:get-offset self ⇒ x-offset y-offset
Method: get-offset self ⇒ x-offset y-offset

Gets the offset previous set with popover:set-offset.

self

Passed: a <GtkPopover>.

a <GtkPopover>

x-offset

Returned: a 32-bit integer.

a location for the x_offset

y-offset

Returned: a 32-bit integer.

a location for the y_offset

Method: popover:get-pointing-to! self rect ⇒ %return rect
Method: get-pointing-to! self rect ⇒ %return rect

Gets the rectangle that the popover points to.

If a rectangle to point to has been set, this function will return #t and fill in rect with such rectangle, otherwise it will return #f and fill in rect with the parent widget coordinates.

self

Passed: a <GtkPopover>.

a <GtkPopover>

rect

Passed, filled in, and returned: a <GdkRectangle>.

location to store the rectangle

%return

Returned: a boolean.

#t if a rectangle to point to was set.

Method: popover:get-position self ⇒ %return
Method: get-position self ⇒ %return

Returns the preferred position of self.

self

Passed: a <GtkPopover>.

a <GtkPopover>

%return

Returned: a <GtkPositionType>.

The preferred position.

Procedure: popover:new ⇒ %return

Creates a new <GtkPopover>.

%return

Returned: a <GtkWidget>.

the new <GtkPopover>

Method: popover:popdown self
Method: popdown self

Pops self down.

This may have the side-effect of closing a parent popover as well. See popover:cascade-popdown.

self

Passed: a <GtkPopover>.

a <GtkPopover>

Method: popover:popup self
Method: popup self

Pops self up.

self

Passed: a <GtkPopover>.

a <GtkPopover>

Method: popover:present self
Method: present self

Allocate a size for the <GtkPopover>.

This function needs to be called in size-allocate by widgets who have a <GtkPopover> as child. When using a layout manager, this is happening automatically.

To make a popover appear on screen, use popover:popup.

self

Passed: a <GtkPopover>.

a <GtkPopover>

Method: popover:set-autohide self autohide
Method: set-autohide self autohide

Sets whether self is modal.

A modal popover will grab the keyboard focus on it when being displayed. Focus will wrap around within the popover. Clicking outside the popover area or pressing Esc will dismiss the popover.

Called this function on an already showing popup with a new autohide value different from the current one, will cause the popup to be hidden.

self

Passed: a <GtkPopover>.

a <GtkPopover>

autohide

Passed: a boolean.

#t to dismiss the popover on outside clicks

Method: popover:set-cascade-popdown self cascade-popdown
Method: set-cascade-popdown self cascade-popdown

If cascade-popdown is #t, the popover will be closed when a child modal popover is closed.

If #f, self will stay visible.

self

Passed: a <GtkPopover>.

A <GtkPopover>

cascade-popdown

Passed: a boolean.

#t if the popover should follow a child closing

Method: popover:set-child self [child]
Method: set-child self [child]

Sets the child widget of self.

self

Passed: a <GtkPopover>.

a <GtkPopover>

child

Passed, or left out: a <GtkWidget>, or #f.

the child widget

Method: popover:set-default-widget self [widget]
Method: set-default-widget self [widget]

Sets the default widget of a <GtkPopover>.

The default widget is the widget that’s activated when the user presses Enter in a dialog (for example). This function sets or unsets the default widget for a <GtkPopover>.

self

Passed: a <GtkPopover>.

a <GtkPopover>

widget

Passed, or left out: a <GtkWidget>, or #f.

a child widget of self to set as the default, or #f to unset the default widget for the popover

Method: popover:set-has-arrow self has-arrow
Method: set-has-arrow self has-arrow

Sets whether this popover should draw an arrow pointing at the widget it is relative to.

self

Passed: a <GtkPopover>.

a <GtkPopover>

has-arrow

Passed: a boolean.

#t to draw an arrow

Method: popover:set-mnemonics-visible self mnemonics-visible
Method: set-mnemonics-visible self mnemonics-visible

Sets whether mnemonics should be visible.

self

Passed: a <GtkPopover>.

a <GtkPopover>

mnemonics-visible

Passed: a boolean.

the new value

Method: popover:set-offset self x-offset y-offset
Method: set-offset self x-offset y-offset

Sets the offset to use when calculating the position of the popover.

These values are used when preparing the <GdkPopupLayout> for positioning the popover.

self

Passed: a <GtkPopover>.

a <GtkPopover>

x-offset

Passed: a 32-bit integer.

the x offset to adjust the position by

y-offset

Passed: a 32-bit integer.

the y offset to adjust the position by

Method: popover:set-pointing-to self [rect]
Method: set-pointing-to self [rect]

Sets the rectangle that self points to.

This is in the coordinate space of the self parent.

self

Passed: a <GtkPopover>.

a <GtkPopover>

rect

Passed, or left out: a <GdkRectangle>, or #f.

rectangle to point to

Method: popover:set-position self position
Method: set-position self position

Sets the preferred position for self to appear.

If the self is currently visible, it will be immediately updated.

This preference will be respected where possible, although on lack of space (eg. if close to the window edges), the <GtkPopover> may choose to appear on the opposite side.

self

Passed: a <GtkPopover>.

a <GtkPopover>

position

Passed: a <GtkPositionType>, or one of its symbols.

preferred popover position

Signals

Signal: popover:activate-default

Connect a handler with (connect object popover:activate-default handler). It is called as (handler self).

Emitted whend the user activates the default widget.

This is a keybinding signal.

The default binding for this signal is Enter.

self

Passed: a <GtkPopover>.

Signal: popover:closed

Connect a handler with (connect object popover:closed handler). It is called as (handler self).

Emitted when the popover is closed.

self

Passed: a <GtkPopover>.

Virtual methods

Virtual method: popover:do-activate-default implementor self

To override it in a new class, give register-type #:vfuncs `((activate-default . ,procedure)). The procedure is called as (procedure self).

implementor

Passed: the class whose implementation to call: <GtkPopover>, or a class that derives from it, or its GType number.

self

Passed: a <GtkPopover>.

Virtual method: popover:do-closed implementor self

To override it in a new class, give register-type #:vfuncs `((closed . ,procedure)). The procedure is called as (procedure self).

implementor

Passed: the class whose implementation to call: <GtkPopover>, or a class that derives from it, or its GType number.

self

Passed: a <GtkPopover>.