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. Load dynmic data into a ComboBox (Musescore, QML)
Forum Updated to NodeBB v4.3 + New Features

Load dynmic data into a ComboBox (Musescore, QML)

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 3 Posters 684 Views 2 Watching
  • 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.
  • R Offline
    R Offline
    rowild
    wrote on last edited by
    #1

    Hi!

    I am new to QML and try to develop a plugin for the notation software Musescore.

    There, I can retrieve all staves of a score like this:

    import QtQuick 2.9
    import QtQuick.Controls.Styles 1.4
    import QtQuick.Layouts 1.3
    import QtQuick.Controls 2.1
    import QtQuick.Dialogs 1.2
    import MuseScore 3.0
    
    MuseScore {
    
      // Is this a correct definition of an array property?
      var staffList
    
      function getStaves(score) {
        for(var i = 0; i < score.parts.length; i++) {
          var part = score.parts[i]
          console.log("part[i]:" + pPartName)
    
          // I would like to push the name to the list like this (but that does not seem to work)
          // staffList.push(score.parts[i])
        }
      }
    }
    

    Unfortunately I have no idea, how to save the staff names to an array of strings. The idea is to assign this string later to the comboBox's model.

    Can anybody please give me a hint, how to do that?

    Thank you!

    A 1 Reply Last reply
    0
    • R rowild

      Hi!

      I am new to QML and try to develop a plugin for the notation software Musescore.

      There, I can retrieve all staves of a score like this:

      import QtQuick 2.9
      import QtQuick.Controls.Styles 1.4
      import QtQuick.Layouts 1.3
      import QtQuick.Controls 2.1
      import QtQuick.Dialogs 1.2
      import MuseScore 3.0
      
      MuseScore {
      
        // Is this a correct definition of an array property?
        var staffList
      
        function getStaves(score) {
          for(var i = 0; i < score.parts.length; i++) {
            var part = score.parts[i]
            console.log("part[i]:" + pPartName)
      
            // I would like to push the name to the list like this (but that does not seem to work)
            // staffList.push(score.parts[i])
          }
        }
      }
      

      Unfortunately I have no idea, how to save the staff names to an array of strings. The idea is to assign this string later to the comboBox's model.

      Can anybody please give me a hint, how to do that?

      Thank you!

      A Offline
      A Offline
      Allon
      wrote on last edited by
      #2

      @rowild Hi,
      If I understand it well you need to create a ListModel, then append the staves in it.

      https://doc.qt.io/qt-5/qml-qtqml-models-listmodel.html

      You will then straight away be able to use the model into your combobox like explained in this page.

      https://doc-snapshots.qt.io/qt5-5.11/qml-qtquick-controls-combobox.html

      Regards,

      Emmanuel

      R 1 Reply Last reply
      0
      • GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        @rowild said in Load dynmic data into a ComboBox (Musescore, QML):

        The idea is to assign this string later to the comboBox's model.

        You should directly be able to assign parts list to a ComboBox model. Use textRole to define the correct role/property to display.

        R 1 Reply Last reply
        2
        • A Allon

          @rowild Hi,
          If I understand it well you need to create a ListModel, then append the staves in it.

          https://doc.qt.io/qt-5/qml-qtqml-models-listmodel.html

          You will then straight away be able to use the model into your combobox like explained in this page.

          https://doc-snapshots.qt.io/qt5-5.11/qml-qtquick-controls-combobox.html

          Regards,

          Emmanuel

          R Offline
          R Offline
          rowild
          wrote on last edited by
          #4

          @Allon Thank you for your answer! I knew about that approach, but I simply have no idea, where and how to put the loop over a score's staves in such a setup. The examples all have hardcoded arrays, but nowhere any for-loop (which would be the way how I think about doing it knowing a bit Javascript).
          Also the ListModel example is a separate file, if I am not mistaken. It creates 3 List Elements. How would I be able to transfer an dynamically calculated array to that file? (While writing, I am thinking of signals... "onListComplete() { MyListItemModel ... but again... there must somehow be a loop somewhere, right? ... }
          Hmmm...

          A 1 Reply Last reply
          0
          • GrecKoG GrecKo

            @rowild said in Load dynmic data into a ComboBox (Musescore, QML):

            The idea is to assign this string later to the comboBox's model.

            You should directly be able to assign parts list to a ComboBox model. Use textRole to define the correct role/property to display.

            R Offline
            R Offline
            rowild
            wrote on last edited by
            #5

            @GrecKo Thank you very much for your input! I got something working, I write more tomorrow!

            1 Reply Last reply
            1
            • R rowild

              @Allon Thank you for your answer! I knew about that approach, but I simply have no idea, where and how to put the loop over a score's staves in such a setup. The examples all have hardcoded arrays, but nowhere any for-loop (which would be the way how I think about doing it knowing a bit Javascript).
              Also the ListModel example is a separate file, if I am not mistaken. It creates 3 List Elements. How would I be able to transfer an dynamically calculated array to that file? (While writing, I am thinking of signals... "onListComplete() { MyListItemModel ... but again... there must somehow be a loop somewhere, right? ... }
              Hmmm...

              A Offline
              A Offline
              Allon
              wrote on last edited by
              #6

              @rowild I think I understand what bother you. There is no loop. You just put all your data in ListModel and the internal repeater will use all of them. Once you change a ListElement in the ListModel it will update its view.
              See here
              https://doc.qt.io/qt-5/qml-qtqml-models-listmodel.html
              With a listview to understand the concept.

              Rectangle {
                  width: 200; height: 200
              
                  ListModel {
                      id: fruitModel
                      ...
                  }
              
                  Component {
                      id: fruitDelegate
                      Row {
                          spacing: 10
                          Text { text: name }
                          Text { text: '$' + cost }
                      }
                  }
              
                  ListView {
                      anchors.fill: parent
                      model: fruitModel
                      delegate: fruitDelegate
                  }
              }
              
              1 Reply Last reply
              0
              • R Offline
                R Offline
                rowild
                wrote on last edited by
                #7

                @Allon Thank you so very much again for your help! I will have a look at it today again and report back.

                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