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: access model properties from delegate

TableView: access model properties from delegate

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 2.5k 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.
  • P Offline
    P Offline
    pablote83
    wrote on last edited by
    #1

    I have a TableView for which I've defined my own itemDelegate. Now, from within this delegate I can access the value for the column using styleData.value, but I'd also need to access the other properties in this same item but I can't find how to.

    I need this, because the text styling needs to change depending on some other property of the item model.

    Any ideas? thanks!

    (btw I also posted this on here: http://stackoverflow.com/questions/22874387/qml-tableview-access-model-properties-from-delegate)

    1 Reply Last reply
    0
    • X Offline
      X Offline
      Xander84
      wrote on last edited by
      #2

      Hi, so if I understand you correctly you want to change the TableView style depending on your model for the current item? Maybe a small code example would help. :)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pablote83
        wrote on last edited by
        #3

        Yea the style thing was probably extra unnecessary info.

        I'm writing a custom "itemDelegate":https://qt-project.org/doc/qt-5.1/qtquickcontrols/qml-qtquick-controls1-tableview.html#itemDelegate-prop.

        The documentation mentions which values are available here. One of them is styleData.value which is the model item for that particular column. What I would like to be able to access is the other columns for the same item model (same row in the table).

        The model is a ListModel composed of ListElements.

        thanks!

        1 Reply Last reply
        0
        • X Offline
          X Offline
          Xander84
          wrote on last edited by
          #4

          Ok I've just seen the TableView is very diffent from the ListView element, I never used the TableView but did you try this:
          @
          model.get(styleData.row).yourColumnProperty
          @
          ?

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pablote83
            wrote on last edited by
            #5

            That makes a lot of sense, I'll give it a try and let you know. :)

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jens
              wrote on last edited by
              #6

              Note. Because of this inconsistence and after considerable debate we actually changed the behaviour of TableView in 5.3 to be more aligned with ListView.

              The "model" property in 5.3 should be the same as it is in ListView. If you try the 5.3 beta, it is already behaving like ListView. Unfortunately, this also means the proposed snippet above will actually stop working.

              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