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

Maurizio Berti maurizio.berti at gmail.com
Fri Feb 8 11:15:37 GMT 2019


>
> Yet again, thank you for your interest.  Though my head is beginning to
> ache over all this now! :)
>

:-)


Until yesterday, I would have claimed that, yes, the QTableView does show
> these python datetimes from the model natively.  Then I noticed in
> something new I was doing that they were coming out blank.  I am beginning
> to believe that you are quite right and it does *not* auto-handle/convert
> them....
>

So I suppose I was right (meaning I was wrong in the first place): datetime
object are not displayed in item views!


Please understand: until a year or so ago I had never used Python or Qt.
> Now I develop & maintain (on my own, so no one I can ask) an existing PyQt
> project with tens of thousands of lines of existing code.  Written by
> different people over years with not a single comment and impenetrable
> logic.  This means I don't always know what's happening where.
>

Don't worry. I've been developing a program in the last year, it's more
than 40k lines of code right now and sometimes I'm completely lost in it. I
couldn't even imagine how that would feel when "inheriting" somebody else's
code!


Since you are enjoying yourself(!), I also claimed that a column with
> Python type decimal.Decimal in it (that's what we use for all our
> monetary numbers, we need two decimal places and no loss of precision so
> float is no good) fails to sort in just the same way as dateime.date.
> Again, there I *thought* some auto-conversion was going to float which
> the sort does know about.  You *might* like to see how that behaves for
> you?  If that too does not sort and does not display correctly (i.e. it's
> not handled intrinsically by model/view code), then again I wonder whether
> we don't have our own explicit code in, say, .data(row, col,
> Qt.DisplayRole) which converts to a fixed-2-decimals string output.  So
> again if it can't be displayed natively I would understand why it can't be
> sorted on.
>

>From what you're describing (including the fact that you don't know the
whole codebase yet), I'd assume that there could be some item delegate in
use somewhere, which can handle non-Qt data types.
If you're not familiar with them, they're the Qt way to "display" data in
an item view (tables, etc.) whenever the printable data content is not
useful enough.
I use them a lot; for example, I've a sqlite database with a "tag" field
which contains a json list, and I use an item delegate linked to another
database table to display the content as a fancy coloured tag list with
rounded corners and mouse hover highlight.
Long story short, item delegates can display custom data type content, so
it is possible that this is your case: somewhere in the code a delegate was
set for an item view (or a column of a table view) and that's why you can
see non-Qt objects as strings, possibly by using displayText() or even
paint().



> I would do this myself today if I could.
>
[...]
>
So today, having never done any PHP and knowing nothing about how it all
> works, I must urgently learn and fix the whole site... trust you understand!
>
> Ciao, e grazie :)
>

Well, I know a bit about PHP (and I've learned to hate it); all I can say
to you is: "good luck, I'm sorry" :-D

Grazie a te ;-)
Maurizio

-- 
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190208/68426ba6/attachment.html>


More information about the PyQt mailing list