Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-113488

Improve QtQuick.Controls Menu performance with many items

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.5.0
    • Quick: Controls 2
    • None
    • All

    Description

      The QtQuick.Controls Menu component is essentially a ListView without support for any of the dynamic instantiation, pooling or caching that ListView supports. Most Menu implementations actually use a ListView internally to show their items but because the Menu contentModel requires the items to be created upfront Menus with many items incur a significant upfront compilation penalty.

      Take for example the Instantiator example found in the docs: https://doc.qt.io/qt-6/qml-qtquick-controls2-menu.html#using-instantiator

      If the Instantiator's model is some list model with many items then all of the MenuItem instances will be created up front regardless of whether they are actually visible in the ListView.

      One way around this is to create a custom Menu with a Popup and a ListView but that doesn't work if you want to show the Menu in a MenuBar for example.

      See the attached Main.qml for an example of this issue. With 1000 menu items the menu takes a few seconds to open.

      QtControls.Menu {
        id: menu
        title: qsTr("Recent Files")
      
        Instantiator {
          active: menu.visible
          
          // Some large model
          model: {
            let array = []
            for (let i = 0; i < 1000; i++) {
              array.push(i + "")
            }
            return array
          }
      
          delegate: QtControls.MenuItem {
            text: modelData
          }
      
          onObjectAdded: (index, object) => menu.insertItem(index, object)
          onObjectRemoved: (index, object) => menu.removeItem(object)
        }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            haiku Ollie Dawes
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes