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. ListModel and GridView
Forum Updated to NodeBB v4.3 + New Features

ListModel and GridView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 3 Posters 839 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.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by
    #1

    I have a model with two QStringList Q_PROPERTY's one is a list of image locations the other is a list of strings. I want to try and display this data in a GridView but I am not sure if I should try to use the data to populate a ListModel or if I should just feed it one of the lists as a the model and envoke the other list with an index. Can I dynamically create ListElement's like that?

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      Create a proper list model in C++ that has everything in one place.

      C++ is a perfectly valid school of magic.

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

        @fcarney I would try to pipe from this model to a proper QAbstractListModel but that seems like a whole lot of work for something that's only going to be used once and in a limited manner.

        1 Reply Last reply
        0
        • AlienA Offline
          AlienA Offline
          Alien
          wrote on last edited by Alien
          #4

          Dear @Circuits ,

          Why you want to use two separate list (like QList) and why you don't just create one QList from your own template class for QList like QList<MyData> which includes your titles and paths of images,icons etc. In this case, I guess you can manage things far easier than before.

          I use QAbstractListModel and it works fine without any special limitation! Could you please offer more information?

          Yours,

          1 Reply Last reply
          0
          • fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by fcarney
            #5

            Here is "a whole lot of work":

            • File->New File or Project->Qt->Qt Item Model
            • Press Choose
            • In Base Class: select QAbstractListModel
            • Name Class
            • Choose options
            • Choose next
            • Choose finish

            Do have to define roles and such, but Qt Creator does the boiler plate crap fairly well.

            C++ is a perfectly valid school of magic.

            C 1 Reply Last reply
            0
            • C Offline
              C Offline
              Circuits
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • fcarneyF fcarney

                Here is "a whole lot of work":

                • File->New File or Project->Qt->Qt Item Model
                • Press Choose
                • In Base Class: select QAbstractListModel
                • Name Class
                • Choose options
                • Choose next
                • Choose finish

                Do have to define roles and such, but Qt Creator does the boiler plate crap fairly well.

                C Offline
                C Offline
                Circuits
                wrote on last edited by Circuits
                #7

                @fcarney Well wouldn't I have to implement an insertRows(), beginInsertRows(), endInsertRows()? The same for columns, or any other method I wish to use? Could I somehow pipe the information from these lists I have already created over too this new class? As of now they are part of a model called settings:

                class SettingV: public QObject
                {
                Q_OBJECT
                Q_PROPERTY(QStringList optionsList      READ optionsList    WRITE setOptionsList    NOTIFY optionsListChanged)
                Q_PROPERTY(QStringList optionsListImages      READ optionsListImages    WRITE setOptionsListImages    NOTIFY optionsListImagesChanged)
                ...
                

                That being said,, the reason I just created a new list is because I already have this ListView component that is displaying the "optionsList" items in a list and I figured it should be easy to just convert that component into a GridView and index off of another list for the images that will be attached to the "optionsList" strings ie the logic is simple:

                for each item in "options List"
                set Image source: property to the corresponding string in the other list

                Since that will be the image url of the image associated with that item because of how I created the lists.. using enums..

                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