TableView rendering issue on Windows 7
-
wrote on 11 Mar 2015, 15:36 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:
And here's how it looks when the model gets updated:
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
-
wrote on 24 Mar 2015, 16:38 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 } }
-
wrote on 7 Apr 2015, 09:16 last edited by Monomix 4 Jul 2015, 09:16
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