[PyQt] QSortFilterProxyModel::sort() not sorting on column types

J Barchan jnbarchan at gmail.com
Fri Feb 1 09:43:13 GMT 2019


I use Qt/PyQt 5.7, the standard distribution supplied for Ubuntu 18.04.

I have a QSortFilterProxyModel wrapped around a QStandardItemModel as its
source model.  I try to use QSortFilterProxyModel::sort() to sort by column
values.

I have a column of Python type datetime.date.  When I call the sort(),
there is no "warning" but *nothing happens*.  The sort does not rearrange
the items at all.  They are initially "randomly" ordered in rows, and the
rows simply retain their current order.  It does *not* even reorder by
string value.  It is as though it simply decides they are "unorderable".

When I sort instead by a Python str column they *do* get reordered.  FWIW,
I have another column of Python type decimal.Decimal and sorting by that
too does nothing, even though I think that should be convertible to float/
double.  However, that may complicate matters so let's stick to the
datetime.date case, I am just mentioning it in case it's relevant.

It took me a long time to realise where the problem lies.  I have a
workaround: I *explicitly* change all my values in the model from
datetime.date to QDate(value) and now it does sort.

But my understanding/experience from other PyQt methods is that it does
this kind of Python type -> QVariant conversion for you behind the scenes
itself.  I shouldn't have to change my types or write special code.

Is this a bug?  Is this in my PyQt 5.7 only?

-- 
Kindest,
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190201/5205cf05/attachment.html>


More information about the PyQt mailing list