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. QAbstractListModel containing a QAbstractListModel for ComboBox QML
Forum Updated to NodeBB v4.3 + New Features

QAbstractListModel containing a QAbstractListModel for ComboBox QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 537 Views 1 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.
  • C Offline
    C Offline
    cirquit
    wrote on last edited by
    #1

    Hi guys,

    I have a QAbstractListModel (let's call it VideoOptions) which is used by a ListView in QML. Now I want to create a drop down list (let's call it Format) for each element (video) in the VideoOptions model, which seems to be a ComboBox in QML.

    Because of this restriction it seems I can't create a Q_INVOKABLE function in VideoOptions to get the correct QAbstractListModel to use in a ComboBox.

    The basic model layout is the following:

    VideoOptions (ListModel)
       -> VideoOption 1 (Element)
             -> Format (ListModel)
                   -> Format 1 (Element)
                   -> Format 2 (Element)
                   -> Format 3 (Element)
       -> VideoOption 2 (Element)
             -> Format (ListModel)
                   -> Format 1 (Element)
                   -> Format 2 (Element)
                   -> Format 3 (Element)
    

    What is the Qt'iest way to solve this? I currently have a very dirty solution by uncoupling the Format ListModel from the VideoOptions ListModel and creating the exact amount of Format ListModels I need and referencing them by unique names e.g formatListModel1, formatListModel2 in QML.

    Another possibility would be to create the Format ListModel's and share them with the VideoOptions Element by a std::shared_ptr and then create a Q_INVOCABLE function in VideoOptions ListModel to access them from QML.

    In both cases I'd be dependent on an explicit index , which I'd like to avoid because it should be only dependent on the amount of VideoOptions instantiated at one single place.

    rrlopezR 1 Reply Last reply
    0
    • C cirquit

      Hi guys,

      I have a QAbstractListModel (let's call it VideoOptions) which is used by a ListView in QML. Now I want to create a drop down list (let's call it Format) for each element (video) in the VideoOptions model, which seems to be a ComboBox in QML.

      Because of this restriction it seems I can't create a Q_INVOKABLE function in VideoOptions to get the correct QAbstractListModel to use in a ComboBox.

      The basic model layout is the following:

      VideoOptions (ListModel)
         -> VideoOption 1 (Element)
               -> Format (ListModel)
                     -> Format 1 (Element)
                     -> Format 2 (Element)
                     -> Format 3 (Element)
         -> VideoOption 2 (Element)
               -> Format (ListModel)
                     -> Format 1 (Element)
                     -> Format 2 (Element)
                     -> Format 3 (Element)
      

      What is the Qt'iest way to solve this? I currently have a very dirty solution by uncoupling the Format ListModel from the VideoOptions ListModel and creating the exact amount of Format ListModels I need and referencing them by unique names e.g formatListModel1, formatListModel2 in QML.

      Another possibility would be to create the Format ListModel's and share them with the VideoOptions Element by a std::shared_ptr and then create a Q_INVOCABLE function in VideoOptions ListModel to access them from QML.

      In both cases I'd be dependent on an explicit index , which I'd like to avoid because it should be only dependent on the amount of VideoOptions instantiated at one single place.

      rrlopezR Offline
      rrlopezR Offline
      rrlopez
      wrote on last edited by
      #2

      @cirquit Hi, I would create first a ListView to contain all the VideoOption items (In this case, VideoOptions ListModel). The delegate of this ListView would be another element which also has a ListView or a repeater (depending on how much functionality from the listview you need) and set its model to the Format ListModel.
      This way the first ListView displays the VideoOption items, each VideoOption item will have a repeater/ListView to show the format ListModel (this element will be the Combo Item) and then, this item would show each of the format elements.
      I hope I made myself clear.

      Lic-Ing. Rodrigo Lopez Gonzalez
      Embedded Software Engineer
      RidgeRun Engineering Ltd.
      www.ridgerun.com
      Email: rodrigo.lopez@ridgerun.com

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cirquit
        wrote on last edited by
        #3

        I think I understood your answer, but this does not allow me to create a QAbstractListModel which consists of VideoOptions which each consist of a QAbstractListModel for Format.

        Your proposed solution would be the one I described, as in "I defined a custom model for each VideoOption which I then plug into QML via formatModel1, formatModel2 and formatModel3.

        Please tell me I understood incorrectly :( Is this a new use-case or am I missing something totally obvious? I can't seem to grasp that I'm the only one who wants to group members of a model in a single QAbstractListModel and not have them independent of each other.

        Or maybe is there another way to create a drop-down ComboBox list without using a QAbstractListModel but still be notified of changes and have the model accessable in C++?

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

          What are the roles of your VideoOptions QALM ?
          Can't you have a role returning your Format QALM?

          It's also kinda hard to help you further since this really depends on your data structure and on how you store your data underneath the model.

          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