Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I want to get the Min and Max values of QStandardItemModel.
Forum Updated to NodeBB v4.3 + New Features

I want to get the Min and Max values of QStandardItemModel.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 454 Views 1 Watching
  • 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1

    appendRow to the value of QStandardItemModel.
    I want to get the Min and Max values based on the column line.

    Do I have to access the index every time to find Min and Max? Please let me know if there is a simpler way

    Christian EhrlicherC JonBJ 2 Replies Last reply
    0
    • I IknowQT

      appendRow to the value of QStandardItemModel.
      I want to get the Min and Max values based on the column line.

      Do I have to access the index every time to find Min and Max? Please let me know if there is a simpler way

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @IknowQT said in I want to get the Min and Max values of QStandardItemModel.:

      Do I have to access the index every time to find Min and Max?

      Yes

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • I IknowQT

        appendRow to the value of QStandardItemModel.
        I want to get the Min and Max values based on the column line.

        Do I have to access the index every time to find Min and Max? Please let me know if there is a simpler way

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @IknowQT
        There are 3 ways you can accomplish this:

        1. Visit every index to determine the min/max in a column. This is presumably the way databases implement MIN/MAX(column), unless column has a database INDEX on it.

        2. Add a QSortFilterProxyModel on top of the QStandardItemModel, sorted by the numeric desired column. Ensure dynamicSortFilter is on, so that it retains the correct, updated sort order when you add a row. Then you know you want the first and the last indexes into the sort filter proxy model.

        3. Maintain your own min & max variables, presumably in a subclass of the QStandardItemModel. Initially calculate them by visiting every index. When you append a row you only need to compare that against your current min/max variables to see if they need updating. Be careful to clear them out and recalculate if you re-fill the model, change its other rows' values, or similar.

        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