Congratulations to our 2022 Qt Champions!

TableView rendering issue on Windows 7

  • 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?



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

    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

  • 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: