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. TableView only ever queries column 0

TableView only ever queries column 0

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

    I have a simple table model written in C++, and I attached a QML TableView to it. I noticed that the TableView only ever queried data for column 0, which seems odd (I do return the correct number of columns, and that number is queried).

    From some examples, I concluded that the TableView get the columns through querying different roles for column 0, so I was able to adapt my model to a ListModel, assign different roles to the columns, and get it to work that way.

    My question: Is the TableView supposed to query only column 0? Is the implementation of columns in term of roles instead of column index the "state of the art" philosophy for table-like models?

    raven-worxR 1 Reply Last reply
    0
    • A Asperamanca

      I have a simple table model written in C++, and I attached a QML TableView to it. I noticed that the TableView only ever queried data for column 0, which seems odd (I do return the correct number of columns, and that number is queried).

      From some examples, I concluded that the TableView get the columns through querying different roles for column 0, so I was able to adapt my model to a ListModel, assign different roles to the columns, and get it to work that way.

      My question: Is the TableView supposed to query only column 0? Is the implementation of columns in term of roles instead of column index the "state of the art" philosophy for table-like models?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @Asperamanca
      IIRC this is normal behavior.
      See the example from the docs:

      TableView {
          TableViewColumn {
              role: "title"
              title: "Title"
              width: 100
          }
          TableViewColumn {
              role: "author"
              title: "Author"
              width: 200
          }
          model: libraryModel
      }
      

      The tableview columns are mapped to roles instead.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      A 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @Asperamanca
        IIRC this is normal behavior.
        See the example from the docs:

        TableView {
            TableViewColumn {
                role: "title"
                title: "Title"
                width: 100
            }
            TableViewColumn {
                role: "author"
                title: "Author"
                width: 200
            }
            model: libraryModel
        }
        

        The tableview columns are mapped to roles instead.

        A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        @raven-worx

        Are columns in table models only kept for compatibility reasons, then?

        raven-worxR 1 Reply Last reply
        0
        • A Asperamanca

          @raven-worx

          Are columns in table models only kept for compatibility reasons, then?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Asperamanca
          no, a QML tableview just differs from the QtWidgets tableview implementation

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          2
          • A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            That would mean I would have to implement my model differently, depending on whether my UI uses widgets or QML. There goes my loose coupling...

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

              You could implement a proxymodel exposing the columns of your original model (used directly in widgets) as roles for QML.

              I'm suprised there isn't already one on GitHub or elsewhere.

              Also you might want to know that there is a new QML TableView in the making, it will be able to handle different columns, it's not yet ready for release though.

              1 Reply Last reply
              2
              • A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #7

                I have found a relatively simple way to create a model that serves both kinds of views equally well, base on this thread.

                Thanks for letting me know about the new view in-the-making. Unfortunately, I realized that Qt Quick Controls 2 are not particularly useful for me, because they lack native OS styling.

                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