Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Menu
QtWS25 Last Chance

QML Menu

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 3.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    webyte
    wrote on last edited by
    #1

    After reading through both the documentation for Menu and the related source code (links listed below), I can't figure out a way to use use the Menu for standalone use. The documentation states it can be used "as a standalone or context menu". It's clear how it can be used as a context menu and in the menubar, but the source code seems to focus on popping the menu up at the mouse cursor. Am I missing something? Is there an easy way to use the Menu element for a standalone menu without jumping through error prone hacking of the internals or recreating the functionality with a custom component? Any and all help is appreciated. Thanks.

    Documentation:
    http://qt-project.org/doc/qt-5.1/qtquickcontrols/qml-qtquick-controls1-menu.html

    Source
    https://qt.gitorious.org/qt/qtquickcontrols/source/109dec4c8c3e5637998f2d1edd1ed8f721097010:src/controls/Menu.qml
    https://qt.gitorious.org/qt/qtquickcontrols/source/109dec4c8c3e5637998f2d1edd1ed8f721097010:src/controls/qquickmenu.cpp
    https://qt.gitorious.org/qt/qtquickcontrols/source/109dec4c8c3e5637998f2d1edd1ed8f721097010:src/controls/qquickmenu_p.h

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Babalas
      wrote on last edited by
      #2

      To us it in a menu bar like for instance ApplicationWindow it is just
      @ menuBar: MenuBar {
      Menu {
      title: qsTr("File")
      MenuItem {
      text: qsTr("Exit")
      onTriggered: Qt.quit();
      }
      }
      }@

      To use it as a context menu do
      @Menu {id: contextMenu ..... }
      MouseArea {
      anchors.fill: thing you want to respond to clicks
      onClicked: {
      if (mouse.button === Qt.RightButton) {
      contextMenu.popup()
      }
      }
      }@

      If the whole app locks up try passing -dograb to your application. I found in debug mode it disables grabbing (for some unknown reason).

      1 Reply Last reply
      0
      • W Offline
        W Offline
        webyte
        wrote on last edited by
        #3

        I appreciate the response, but I'm not quite sure it addresses my question. Both of those are well documented and make perfect sense. It's using the menu for a standalone menu, which the documentation claims is one of the potential uses, that I'm not clear on. Thanks.

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          Hi,

          In the documentation, "standalone menu" = "context menu" = "popup menu" = not-bound-to-the-menubar menu. (Personally, I wouldn't use the word "standalone" here)

          The other 2 menu types are bound to the menu bar either directly ("top-level menu") or indirectly ("submenu"). The Qt Quick Controls Menu doesn't provide other kinds of menus; the first sentence in the documentation says, "[The QML Menu type] provides a menu component for use in menu bars, as context menu, and other popup menus."

          I believe you're looking for something that lets you implement a main menu or sidebar menu? For this use case, create a row/column/grid of "Buttons":http://qt-project.org/doc/qt-5.1/qtquickcontrols/qml-qtquick-controls1-button.html or "Rectangles":http://qt-project.org/doc/qt-5.1/qtquick/qml-qtquick2-rectangle.html

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • W Offline
            W Offline
            webyte
            wrote on last edited by
            #5

            Thanks JKSH. I suspected that might be the case after reading through the code. It's unfortunate since there is a lot of overlapping code (keyboard handling, stack / visibility management, sub menus, etc) that could be useful for normal standalone menus. That said, it's not too hard to create a custom one. I appreciate the help.

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              You're welcome :)

              [quote author="webyte" date="1381124811"]It's unfortunate since there is a lot of overlapping code (keyboard handling, stack / visibility management, sub menus, etc) that could be useful for normal standalone menus.[/quote]Yes, it's true that there's lots of reusable code here.

              A bit of history will probably provide insight to why the components are designed this way: The Qt Quick Controls module was created because users wanted a way to create classic desktop style applications (think Microsoft Office 2003 or LibreOffice, and their config dialogs). These classic GUIs didn't use "standalone" menus, so Qt Quick Controls doesn't provide them either.

              In any case, games (and more recently, websites and phone apps) typically implement vastly different styles of standalone menus, each with their own unique look-and-feel, animations, behaviours, etc. I'd imagine that it would be hard to create a menu component that can be satisfactorily customized to match the multitude of styles out there.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved