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: ReferenceError: styleData is not defined
Forum Updated to NodeBB v4.3 + New Features

TableView: ReferenceError: styleData is not defined

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 186 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.
  • W Offline
    W Offline
    woodpecker
    wrote on last edited by
    #1

    Hello!
    I wrote this code :

    import QtQuick
    import QtQuick.Window
    import QtQuick.Controls
    import QtQuick.Layouts
    import Qt.labs.qmlmodels
    
     ...
    
     TableView {
        id: tableView
        ...
        model: myModel
        
        delegate: Rectangle {
                    implicitWidth: 100
                    implicitHeight: 50
                    border.width: 1
        
                   Text {
                        text:  styleData.Value
                        anchors.centerIn: parent
                        onTextChanged: console.log(styleData.row)
                    }
                }
       }
    

    An error appears when launching this application:
    "ReferenceError: styleData is not defined".

    The Qt version is 6.8.2.
    I can't find anything about this error.
    Has anyone come across this?
    Thanks in advance!

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bob64
      wrote on last edited by
      #2

      It looks like you are basing your code on an example for the Quick Controls 1 version of TableView, which was deprecated in the final releases of Qt 5 and was removed entirely from Qt 6. The version of TableView that exists in Qt 6 is a completely different implementation and does not use styleData.

      W 1 Reply Last reply
      0
      • B Bob64

        It looks like you are basing your code on an example for the Quick Controls 1 version of TableView, which was deprecated in the final releases of Qt 5 and was removed entirely from Qt 6. The version of TableView that exists in Qt 6 is a completely different implementation and does not use styleData.

        W Offline
        W Offline
        woodpecker
        wrote on last edited by
        #3

        @Bob64 said in TableView: ReferenceError: styleData is not defined:

        which was deprecated in the final releases of Qt 5

        Yes, it is.
        But I need a different appearance of the cells depending on the column or role.
        How do I do this in Qt 6?
        I found the DelegateChoice class:
        https://doc.qt.io/qt-6.8/qml-qt-labs-qmlmodels-delegatechoice.html .
        Is that what I need?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Bob64
          wrote on last edited by Bob64
          #4

          It depends how different your delegates need to be. DelegateChoice is good for cases where you need fundamentally different delegates depending on the role etc. If it is just some small variations in appearance that you need, such as a different colour of something, you might just be able to code such variation directly in a single delegate. Note that in Qt 6 TableView things like index, row, column as well as the role values are exposed to the delegate directly as properties.

          As a trivial example of what I mean about coding the logic directly in the delegate:

           delegate: Rectangle {
                ...
               color: column % 2 ? "red" : "blue"
           }
          
          W 1 Reply Last reply
          1
          • B Bob64

            It depends how different your delegates need to be. DelegateChoice is good for cases where you need fundamentally different delegates depending on the role etc. If it is just some small variations in appearance that you need, such as a different colour of something, you might just be able to code such variation directly in a single delegate. Note that in Qt 6 TableView things like index, row, column as well as the role values are exposed to the delegate directly as properties.

            As a trivial example of what I mean about coding the logic directly in the delegate:

             delegate: Rectangle {
                  ...
                 color: column % 2 ? "red" : "blue"
             }
            
            W Offline
            W Offline
            woodpecker
            wrote on last edited by
            #5

            @Bob64 Thanks for the detailed reply!

            1 Reply Last reply
            0
            • W woodpecker has marked this topic as solved on

            • Login

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