Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Questions about models, items and views

Questions about models, items and views

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 317 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.
  • P Offline
    P Offline
    Perdrix
    wrote on 29 Oct 2020, 13:54 last edited by
    #1

    I want to display some data that is tabular in form. There is no hierarchy. The model can be the data store

    I want to have a check box and Icon in the first column of the data, and I want to be able to set attributes of a row by their name rather than by index. QStandardItemModel and QStandardItem appear to do a lot of what I want (as I am sure they are intended to):

    1. Can I use QStandardItemModel/QStandardItem in a way that allows me to access the elements of each row by name, if so how can I do that?

    2. If not is there a model that I can readily subclass that will allow access by column name and also allows use of an Icon and check box. If so how should I proceed to do that? Assume that the underlying data will be a structure/class of QStrings, or possible QStrings and integers. Say for the sake of argument that it has three members of type QString called File, Type and Score.

    3. Will a QTableView work to display the model? The final display should look like:

    66b63299-59db-4006-b93b-7bafe8c68022-image.png

    Thanks
    David

    V 1 Reply Last reply 29 Oct 2020, 14:02
    0
    • P Offline
      P Offline
      Perdrix
      wrote on 29 Oct 2020, 14:30 last edited by
      #3

      What do you mean "by name"

      I mean I want to be able to access item.File, item.Type, item.Score rather than only having access by an index into an array of QStrings

      1 Reply Last reply
      0
      • P Perdrix
        29 Oct 2020, 13:54

        I want to display some data that is tabular in form. There is no hierarchy. The model can be the data store

        I want to have a check box and Icon in the first column of the data, and I want to be able to set attributes of a row by their name rather than by index. QStandardItemModel and QStandardItem appear to do a lot of what I want (as I am sure they are intended to):

        1. Can I use QStandardItemModel/QStandardItem in a way that allows me to access the elements of each row by name, if so how can I do that?

        2. If not is there a model that I can readily subclass that will allow access by column name and also allows use of an Icon and check box. If so how should I proceed to do that? Assume that the underlying data will be a structure/class of QStrings, or possible QStrings and integers. Say for the sake of argument that it has three members of type QString called File, Type and Score.

        3. Will a QTableView work to display the model? The final display should look like:

        66b63299-59db-4006-b93b-7bafe8c68022-image.png

        Thanks
        David

        V Offline
        V Offline
        VRonin
        wrote on 29 Oct 2020, 14:02 last edited by
        #2

        @Perdrix said in Questions about models, items and views:

        the elements of each row by name

        What do you mean "by name"?

        Will a QTableView work to display the model?

        Yes

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Perdrix
          wrote on 29 Oct 2020, 14:30 last edited by
          #3

          What do you mean "by name"

          I mean I want to be able to access item.File, item.Type, item.Score rather than only having access by an index into an array of QStrings

          1 Reply Last reply
          0
          • V Offline
            V Offline
            VRonin
            wrote on 29 Oct 2020, 14:46 last edited by VRonin
            #4

            what you normally do is set an enumerator to determine the columns:

            enum ModelColumns{
            mcFile
            , mcType
            , mcScore
            };
            

            then you use model->item(row,mcFile) to access it using QStandardItemModel (or generically, to read/write model->index(row,mcFile).data()/model->setData(model->index(row,mcFile),QStringLiteral("Something")))

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            2
            • P Offline
              P Offline
              Perdrix
              wrote on 29 Oct 2020, 15:20 last edited by
              #5

              OK! That will get the job done!

              Thanks - it's not knowing the idioms that always catches you out.

              1 Reply Last reply
              0

              3/5

              29 Oct 2020, 14:30

              • Login

              • Login or register to search.
              3 out of 5
              • First post
                3/5
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved