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. Other property.criteria for sections ?
Forum Updated to NodeBB v4.3 + New Features

Other property.criteria for sections ?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 479 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.
  • R Offline
    R Offline
    Ragoudcep
    wrote on last edited by
    #1

    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 ! :)

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      3
      • R Offline
        R Offline
        Ragoudcep
        wrote on last edited by
        #3

        Thank you Grecko, very much !

        I'll try tou use it !

        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