<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Nested Menu with Instantiator]]></title><description><![CDATA[<p dir="auto">Hello all!</p>
<p dir="auto">Is it possible to create context Menu with nested Menu's based on models with Instantiators? I have my own model of items (with the appropriate fields (name and value), each model has it's own model (with the different type).</p>
<p dir="auto">I have tried the following code (and some slightly different versions), but it displays everything in the one menu, without nesting.</p>
<pre><code>Menu {
   id: _menuDevices
   cascade: true

   Instantiator {
      id: _instantiator
      model: backend.getDevicesModel().getObjectsModel()

      delegate: MenuItem {
      width: _menuDevices.width, height: 50
      text: model.name

      property QtObject device: model.pointer

      Menu {
         id: _menuParameters
         cascade: true

         Instantiator {
            id: _instantiatorInner
            model: device.getDeviceParametersModel().getObjectsModel()

            delegate: MenuItem {
               width: _menuParameters.width, height: 50
               text: model.name
            }

            onObjectAdded: _menuParameters.insertItem(index, object)
            onObjectRemoved: _menuParameters.removeItem(object)
            }
         }
      }	

      onObjectAdded: _menuDevices.insertItem(index, object)
      onObjectRemoved: _menuDevices.removeItem(object)
      }
   }
</code></pre>
<p dir="auto">But in this approach I can see only the first level menu without nested ones. Looks like it happens cause inner Menus aren't direct children of the upper Menu's.</p>
<p dir="auto">So question is: can I do what I've wanted? (and how if it's possible?)</p>
]]></description><link>https://forum.qt.io/topic/130068/nested-menu-with-instantiator</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 10:46:42 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/130068.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 06 Sep 2021 14:50:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Nested Menu with Instantiator on Tue, 07 Sep 2021 08:55:16 GMT]]></title><description><![CDATA[<p dir="auto">Here I'm going to continue my classical "question-answer approach". After some time of research, I have found some mistakes in the code: upper level <code>MenuItem</code>s should be replaced with <code>Menu</code>s and signals-slots should be redefined as follows:</p>
<pre><code>	   onObjectAdded: _menuDevices.insertMenu(index, object)
	   onObjectRemoved: _menuDevices.removeMenu(object)
</code></pre>
<p dir="auto"><code>insertMenu</code> and <code>removeMenu</code> should be used instead of <code>insertItem</code> and <code>removeItem</code> accordingly. It's very obvious thing, but it took some time to understand it in the context of the issue.</p>
]]></description><link>https://forum.qt.io/post/679512</link><guid isPermaLink="true">https://forum.qt.io/post/679512</guid><dc:creator><![CDATA[St.Stanislav]]></dc:creator><pubDate>Tue, 07 Sep 2021 08:55:16 GMT</pubDate></item></channel></rss>