Popup Menus

Menus are normally just added to a window, but they can also be displayed temporarily as the result of a mouse button click. For instance, a context menu might be displayed when the user clicks their right mouse button.

For instance:

Glib::ustring ui_info =
  "  <menu id='menu-examplepopup'>"
  "    <section>"
  "      <item>"
  "        <attribute name='label' translatable='yes'>Edit</attribute>"
  "        <attribute name='action'>examplepopup.edit</attribute>"
  "      </item>"
  "      <item>"
  "        <attribute name='label' translatable='yes'>Process</attribute>"
  "        <attribute name='action'>examplepopup.process</attribute>"
  "      </item>"
  "      <item>"
  "        <attribute name='label' translatable='yes'>Remove</attribute>"
  "        <attribute name='action'>examplepopup.remove</attribute>"
  "      </item>"
  "    </section>"
  "  </menu>"


auto gmenu = m_refBuilder->get_object<Gio::Menu>("menu-examplepopup");

To show the popup menu, use a Gtk::EventControllerClick and connect to its pressed signal. In the signal handler, use Gtk::PopoverMenu's popup() method. For instance:

void ExampleWindow::on_label_pressed(int /* n_press */, double x, double y)
  const Gdk::Rectangle rect(x, y, 1, 1);