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. Creating dynamic submenus with repeaters?
Forum Updated to NodeBB v4.3 + New Features

Creating dynamic submenus with repeaters?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 1.4k 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.
  • L Offline
    L Offline
    lagarkane
    wrote on 26 Sept 2019, 16:42 last edited by
    #1

    Hi!
    Does anyone know how to dynamically add subMenus to another Menu?

    I have a dynamic number of 'Menu' that I would like to add to another Menu using a repeater.
    Sadly, while I've already successfully used repeaters to add 'MenuItem' to another Menu, I get the following error when trying to add submenus (Menu) instead of menuItems:

    "QML Component: Delegate must be of Item type"

    I've tried multiple approaches to counter the issue, starting with wrapping the menu in an Item, which did not work.

    Looking fwd to your input!

    O 1 Reply Last reply 26 Sept 2019, 17:22
    0
    • L lagarkane
      26 Sept 2019, 16:42

      Hi!
      Does anyone know how to dynamically add subMenus to another Menu?

      I have a dynamic number of 'Menu' that I would like to add to another Menu using a repeater.
      Sadly, while I've already successfully used repeaters to add 'MenuItem' to another Menu, I get the following error when trying to add submenus (Menu) instead of menuItems:

      "QML Component: Delegate must be of Item type"

      I've tried multiple approaches to counter the issue, starting with wrapping the menu in an Item, which did not work.

      Looking fwd to your input!

      O Offline
      O Offline
      ODБOï
      wrote on 26 Sept 2019, 17:22 last edited by ODБOï
      #2

      @lagarkane hi
      the complete error was

      qrc:/main.qml:29:12: QML Component: Delegate must be of Item type
      ASSERT: "objectRef == 0" in file types\qqmldelegatemodel.cpp, line 2079
      19:23:26: Le programme s'est terminé subitement.
      

      thats because Menu is a Popup, but delegate must be Item

      i used Repeater with a Loader and wrapped Menu in a Component, it worked

      import QtQuick 2.12
      import QtQuick.Window 2.12
      import QtQuick.Controls 2.12
      
      ApplicationWindow {
          id: root
          width: 800
          height: 600
          visible: true
      
          Button {
              id: fileButton
              text: "File..."
              onClicked: menu.open()
      
              Menu {
                  id: menu
                  y: fileButton.height
      
                  MenuItem{
                      text: "item 1"
                  }
      
                  Repeater{
                      id:menuLoader
                      model:3
                      Loader{
                          sourceComponent: sb
                          onStatusChanged:status === Loader.Ready ? console.log("sub men "+index + " loaded") : console.log("!ok")
                      }
                  }
              }
          }
      
          //--
          Component{
              id:sb
              Button{ // you can delete button if you want.
                  text: "New"
                  onClicked: sub.open()
                  Menu{
                      id: sub
                      MenuItem{
                          text: "sub menu item"
                      }
                  }
              }
          }
      }
      
      
      
      1 Reply Last reply
      0
      • G Offline
        G Offline
        GrecKo
        Qt Champions 2018
        wrote on 26 Sept 2019, 17:40 last edited by
        #3

        Use an Instantiator instead of a Repeater

        1 Reply Last reply
        0

        1/3

        26 Sept 2019, 16:42

        • Login

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