Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to add a header for QtQuick TableView in Qt-5.12?



  • Is there a best way to do this? There is one video on youtube but the header is not sticky at the top. There are some entries on this forum but none are really sufficient. Is this seven technically possible? If not, then woah.



  • Hi!
    I couldn't understand what exactly you want. But maybe something like this would work?

    TableView {
        TableViewColumn {
            role: "header1"
            title: "Header 1"
            width: 100
        }
        TableViewColumn {
            role: "header2"
            title: "Header 2"
            width: 200
        }
        TableViewColumn {
            role: "header3"
            title: "Header 4"
            width: 300
        }
        model: myModel
    }
    
    ListModel {
        id: myModel
        ListElement {
            header1: "header1 text 1"
            header2: "header2 text 1"
            header3: "header3 text 1"
        }
        ListElement {
            header1: "header1 text 2"
            header2: "header2 text 2"
            header3: "header3 text 2"
        }
        ListElement {
            header1: "header1 text 3"
            header2: "header2 text 3"
            header3: "header3 text 3"
        }
        ListElement {
            header1: "header1 text 4"
            header2: "header2 text 4"
            header3: "header3 text 4"
        }
    }
    

    Maybe you can describe your needs in a more spesific way :D



  • @closx said in How to add a header for QtQuick TableView in Qt-5.12?:

    Hi!
    I couldn't understand what exactly you want. But maybe something like this would work?

    TableView {
        TableViewColumn {
            role: "header1"
            title: "Header 1"
            width: 100
        }
        TableViewColumn {
            role: "header2"
            title: "Header 2"
            width: 200
        }
        TableViewColumn {
            role: "header3"
            title: "Header 4"
            width: 300
        }
        model: myModel
    }
    
    ListModel {
        id: myModel
        ListElement {
            header1: "header1 text 1"
            header2: "header2 text 1"
            header3: "header3 text 1"
        }
        ListElement {
            header1: "header1 text 2"
            header2: "header2 text 2"
            header3: "header3 text 2"
        }
        ListElement {
            header1: "header1 text 3"
            header2: "header2 text 3"
            header3: "header3 text 3"
        }
        ListElement {
            header1: "header1 text 4"
            header2: "header2 text 4"
            header3: "header3 text 4"
        }
    }
    

    Maybe you can describe your needs in a more spesific way :D

    I am not asking about the TableView from QtQuick.Controls but the new QtQuick TableView. The question is straightforward considering that - how to add a header that works like the header in QTableView.


  • Moderators

    @patrickkidd
    you don't,

    The QuickControlls 2 TableView is very very new. It came with 5.12 and is still work in progress.

    Maybe 5.13 adds something? I haven't check yet.

    You'll have to create your own header component, unfortunately



  • @patrickkidd said in How to add a header for QtQuick TableView in Qt-5.12?:

    I am not asking about the TableView from QtQuick.Controls but the new QtQuick TableView. The question is straightforward considering that - how to add a header that works like the header in QTableView.

    Oh, I have just learned about it :D
    Good work!


  • Moderators

    @patrickkidd said in How to add a header for QtQuick TableView in Qt-5.12?:

    I am not asking about the TableView from QtQuick.Controls but the new QtQuick TableView. The question is straightforward considering that - how to add a header that works like the header in QTableView.

    https://blog.qt.io/blog/2018/08/29/tableview/

    Other than this, the API for the first release of TableView is kept pretty small and strict. More will be implemented later, such as using custom transitions when adding or removing rows and columns. We’re also working on a TableHeader, TableModel, as well as a DelegateChooser. The latter lets you assign several delegates to a TableView, and e.g use a different one for each column. The latter will already be available in Qt 5.12 as a labs import (Qt.labs.qmlmodels 1.0).



  • @raven-worx said in How to add a header for QtQuick TableView in Qt-5.12?:

    @patrickkidd said in How to add a header for QtQuick TableView in Qt-5.12?:

    I am not asking about the TableView from QtQuick.Controls but the new QtQuick TableView. The question is straightforward considering that - how to add a header that works like the header in QTableView.

    https://blog.qt.io/blog/2018/08/29/tableview/

    Other than this, the API for the first release of TableView is kept pretty small and strict. More will be implemented later, such as using custom transitions when adding or removing rows and columns. We’re also working on a TableHeader, TableModel, as well as a DelegateChooser. The latter lets you assign several delegates to a TableView, and e.g use a different one for each column. The latter will already be available in Qt 5.12 as a labs import (Qt.labs.qmlmodels 1.0).

    Thanks for the tip. Will there be a way to draw certain columns in a custom manner, like the following question: https://forum.qt.io/topic/104441/custom-painting-in-listview-along-many-rows/2


Log in to reply