I want to get the Min and Max values of QStandardItemModel.
-
@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
-
@IknowQT
There are 3 ways you can accomplish this:-
Visit every index to determine the min/max in a column. This is presumably the way databases implement
MIN
/MAX(column)
, unlesscolumn
has a databaseINDEX
on it. -
Add a
QSortFilterProxyModel
on top of theQStandardItemModel
, sorted by the numeric desired column. EnsuredynamicSortFilter
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. -
Maintain your own
min
&max
variables, presumably in a subclass of theQStandardItemModel
. Initially calculate them by visiting every index. When you append a row you only need to compare that against your currentmin
/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.
-