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. Using QML TableView + HorizontalHeaderView with QSortFilterProxyModel doesn't show header column
Forum Updated to NodeBB v4.3 + New Features

Using QML TableView + HorizontalHeaderView with QSortFilterProxyModel doesn't show header column

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 42 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.
  • L Offline
    L Offline
    Leooooooooo
    wrote last edited by
    #1

    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
                    }
                }
            }
        }
    
    
    1 Reply Last reply
    0

    • Login

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