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

Other property.criteria for sections ?



  • Hello,

    Hi,

    I'm asking me if it's possible to use other "criteria" than "FirtCharacter" and "FullString" with the "section.criteria" to tableview's section.
    For exemple, , i need to pick the two firsts characters of the "section.property", to exctract some data and sort it.
    I've the property "12:30" and i want to extract "12" to display it in row section, and not just pick the first character "1".

    I don't find any solution, but i hope there a solution somewhere...
    Thank you !

    Sorry for my approximative english, i do my best ! :)


  • Qt Champions 2018

    Hi & Hello,

    Dont't worry about your english, it's fine and perfectly understandable.

    I created a library that fits your needs : SortFilterProxyModel
    It lets you create new roles based on the one from the source model (you can also filter and sort rows with it).

    In your case you might use it like so in your QML file:

    import SortFilterProxyModel 0.2
    
    // ...
    
    SortFilterProxyModel {
        id: proxyModel
        sourceModel: yourModel
        proxyRoles: RegExpRole {
            roleName: "time"
            pattern: "(?<hours>\\d\\d):(?<minutes>\\d\\d)"
        }
    }
    
    TableView {
        model: proxyModel
        section.property: "hours"
        // ...
    }
    

    The SortFilterProxyModel will create a hours and a minutes role from your time role via the RegExpRole.
    The RegExpRole. exposes a new role for each named capture group of its pattern.

    An alternative to this solution could be creating a proxy model yourself in c++, you don't need all the bell and whistles of mine to do what you need.
    Or you could modify the source model to add a new role for the hours directly.



  • Thank you Grecko, very much !

    I'll try tou use it !


Log in to reply