Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved TableView rendering issue on Windows 7

    QML and Qt Quick
    qt quick qml qt 5.3 tableview
    1
    3
    1468
    Loading More Posts
    • 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.
    • Monomix
      Monomix last edited by A Former User

      Howdy all,

      I'm experiencing an interesting quirk of a dynamically-populated TableView in a QML app; when the associated QAbstractTableModel is updated, the table isn't displayed correctly. Sometimes even-numbered row text is not displayed, sometimes the row heights are screwed up, sometimes I see nothing. If I do a column sort on the table, or if I reposition the application window using the Windows key + arrow method, then it's displayed correctly.

      An example, to illustrate; this is how it should look:

      This is good

      And here's how it looks when the model gets updated:

      This is not good

      The TableView itself is instantiated within an Item, which is in turn instantiated within an ApplicationWindow.

      Any ideas on how to get the table displaying correctly?

      Cheers,

      Garry

      1 Reply Last reply Reply Quote 0
      • Monomix
        Monomix last edited by Monomix

        So, here's a video illustrating this issue properly:

        http://www.enclustra.com/assets/temp/TableView.mp4

        Can anyone suggest where I should look to dig for more info on this in the Qt Quick source code? To me it smells like a bug; the QAbstractTableModel is set via context property, and in QML the TableView is simple:

                TableView {
                    id: propertiesTable
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    enabled: rowCount > 0
                    frameVisible: true
                    headerVisible: true
                    sortIndicatorVisible: true
                    alternatingRowColors: true
                    model: standardConfigurationPropertiesTableModel
        
                    onSortIndicatorColumnChanged: {
                        model.sort(sortIndicatorColumn, sortIndicatorOrder)
                    }
                    onSortIndicatorOrderChanged: {
                        model.sort(sortIndicatorColumn, sortIndicatorOrder)
                    }
        
                    TableViewColumn {
                        id: nameColumn
                        role: "standardConfigPropertyDescription"
                        title: qsTr("Property")
                        width: propertiesTable.width / 2 - 1
                        resizable: false
                    }
                    TableViewColumn {
                        id: valueColumn
                        role: "standardConfigPropertyValue"
                        title: qsTr("Value")
                        width: propertiesTable.width / 2 - 1
                        resizable: false
                    }
                }
        
        1 Reply Last reply Reply Quote 0
        • Monomix
          Monomix last edited by Monomix

          Turns out this was a threading issue. The object that contained my QAbstractTableModel-derived models had been moved to a worker thread, which doesn't work well with the model/view architecture - both the GUI thread and the worker thread were sending signals to the models, which meant that insert row and remove row operations were overlapping each other, hence the odd behaviour.

          The main take-out is: when using the model/view approach, the models must have the same thread affinity as the views (i.e. keep the models on the main application thread); don't move them to worker threads unless you want to get jiggy with serialising access.

          A thread that did help: http://stackoverflow.com/questions/9485339/design-pattern-qt-model-view-and-multiple-threads

          1 Reply Last reply Reply Quote 0
          • First post
            Last post