Popup Menus
| Chapter 15. Menus and Toolbars |

## Popup Menus

`Menu`s 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 =
      "<interface>"
      "  <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>"
      "</interface>";

    m_refBuilder->add_from_string(ui_info);

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

To show the popup menu, use a `Gtk::GestureClick` 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);
      m_MenuPopup.set_pointing_to(rect);
      m_MenuPopup.popup();
    }

Menubar and Toolbar |  | Gio::Resource and glib-compile-resources