Using QML TableView + HorizontalHeaderView with QSortFilterProxyModel doesn't show header column
-
I've been using QML TableView + HorizontalHeaderView with QAbstractTableModel as the model for a while now and wanted to implment filtering/sorting. So I've made a QSortFilterProxyModel and changed the model in QML to this proxy model.
When I do this the header column "HorizontalHeaderView" switches to using the data method instead of the headerData, and it switches to now using the rowCount method, so the header has multiple rows just like my tableview. Any ideas if I'm missing something I need to implment in the proxy model? I've tried adding the headerData in there without any luck as it seems it just doesn't call the method anymore with the proxy model set.
This is the HorizontalHeaderView that works without issues with my QAbstractTableModel model but not the proxy one.
Though the problem is fixed if I change the model to using "tableView.model.sourceModel" but this will cause issues I think down the line when I do sorting as the header won't be synced to the proxy model
HorizontalHeaderView { id: horizontalHeader Layout.fillWidth: true syncView: tableView model: tableView.model boundsBehavior: tableView.boundsBehavior clip: tableView.clip resizableColumns: tableView.resizableColumns delegate: HorizontalHeaderViewDelegate { id: horizontalDelegate required property int index background: Rectangle { anchors.fill: horizontalDelegate color: Theme.color.primaryBackground } contentItem: BaseText { text: horizontalDelegate.model.display ?? null anchors.fill: horizontalDelegate horizontalAlignment: Text.AlignLeft leftPadding: Theme.spacing.small rightPadding: Theme.spacing.small font.weight: Theme.typography.weight.emphasized } Rectangle { // bottom border anchors.bottom: parent.bottom width: parent.width height: 2 color: Theme.color.border } // Drag handler Rectangle { width: 20 height: horizontalDelegate.height anchors.right: horizontalDelegate.right anchors.verticalCenter: horizontalDelegate.verticalCenter color: "transparent" DragHandler { property real startWidth onActiveChanged: { if (active) { startWidth = horizontalDelegate.width } } onTranslationChanged: { let newWidth = Math.max(tableView.minColumnWidths[horizontalDelegate.index], startWidth + translation.x) tableView.columnWidths[horizontalDelegate.index] = newWidth tableView.adjustLastColumn() tableView.forceLayout() } target: null xAxis.enabled: true yAxis.enabled: false } HoverHandler { cursorShape: Qt.SizeHorCursor } } } }