<div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div style="font-family:tahoma,sans-serif">This does not matter now, in that I have a workaround, but I'll ask you one more time.  The example you give talks about converting <span style="font-family:monospace,monospace">QDateTime</span>s to <span style="font-family:monospace,monospace">QDate</span>s.  Please forget about <span style="font-family:monospace,monospace">QDateTime</span>, that is not the issue I am asking about.  As long as your original code only uses the Qt native types like <span style="font-family:monospace,monospace">QDate</span> or <span style="font-family:monospace,monospace">QDateTime</span> there will be no problem sorting.  I understand that.<br></div><div style="font-family:tahoma,sans-serif"><br></div><div style="font-family:tahoma,sans-serif">My code uses the <i>Python</i> types from the <span style="font-family:monospace,monospace">datetime</span> module.  <span style="font-family:monospace,monospace">datetime.date</span> is a Python date type.  In all other places I have made PyQt calls it always correctly converts between, say, Python type <span style="font-family:monospace,monospace">datetime.date</span> and Qt type <span style="font-family:monospace,monospace">QDate</span>, in either direction, as necessary.  I do not have to do anything special in my code.  The PyQt wrappers for arguments etc. are doing it for me.  This is a huge (good) point about PyQt.<br></div></div></div></blockquote><div><br></div><div>I'm sorry, Jonathan: I think I didn't read your first message carefully enough, and then I didn't take the "Python type datetime" into account.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div style="font-family:tahoma,sans-serif">The <i>only</i> question I do not understand/would like answered is: why do I have to use <span style="font-family:monospace,monospace">QDate</span> and not <span style="font-family:monospace,monospace">datetime.date</span> in the model to make just <span style="font-family:monospace,monospace">QSortFilterProxyModel::sort()</span> work, when everything other than that works fine with <span style="font-family:monospace,monospace">datetime.date</span>?  Why does PyQt auto-conversion between Python <span style="font-family:monospace,monospace">datetime.date</span> and Qt <span style="font-family:monospace,monospace">QDate</span> work everywhere other than during <span style="font-family:monospace,monospace">QSortFilterProxyModel.sort()</span>?<br></div></div></div></blockquote></div><div><br>Well, I'm just guessing an answer here; it's possible that in every other situation the conversion is done automatically since you're doing operations involving unambiguous treatment of the date object, for example when setting a QDateTimeEdit date, or, in this case, display the date in the table field.</div><div>The sort() method instead attempts to sort by "guessing" the preferred sorting criteria according to the content of the field, which is not unique. You could have strings, floats and datetimes in the same column and *maybe* that's why the automatic conversion doesn't work properly in this case: while QDateTime is directly recognized by lessThan() along with other QVariant types, Python's datetime is not "native" to Qt and I suppose that it just doesn't know what to do with it (do you want to compare it as a string? as a number? as a QDate? as a QDateTime?), then I think it just "leaves" the object as it is, without doing any comparison.</div><div><br>Again, this is just a guess, tonight I'll check the sources and maybe I'll find out a better answer.</div><div dir="ltr"><br></div>Maurizio<br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div></div></div></div>