<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 30 Jul 2019 at 09:16, Gottfried Müller <<a href="mailto:gottfried.mueller@gmx.de">gottfried.mueller@gmx.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br>
<br>
in a simple test I want to sort the items in an ascending order using my <br>
own proxy. I expected a comparision of "<span class="gmail_default" style="font-family:tahoma,sans-serif"></span>itemLeft.text() < <br>
itemRight.text()". But I had to code "itemRight.text() < <br>
itemLeft.text()" getting the ascending order.<br>
<br>
Gottfried<br>
<br>
Here is my example:<br>
<br>
#!/usr/bin/env python3<br>
# -*- coding: utf-8 -*-<br>
# pylint: disable=missing-docstring<br>
<br>
import sys<br>
<br>
from PyQt5.QtWidgets import QApplication, QTreeView<br>
from PyQt5.QtGui import QStandardItemModel, QStandardItem<br>
from PyQt5.QtCore import QSortFilterProxyModel<br>
<br>
<br>
class MyProxy(QSortFilterProxyModel):<br>
<br>
def lessThan(self, mdlIdxSrcLeft, mdlIdxSrcRight):<br>
mdl = self.sourceModel()<br>
itemLeft = mdl.itemFromIndex(mdlIdxSrcLeft)<br>
itemRight = mdl.itemFromIndex(mdlIdxSrcRight)<br>
return itemRight.text() < itemLeft.text()<br>
<br>
# def filterAcceptsRow(self, srcRow, srcParentIdx):<br>
# mdl = self.sourceModel()<br>
# itemParent = mdl.itemFromIndex(srcParentIdx)<br>
# if itemParent is None:<br>
# srcItem = mdl.item(srcRow)<br>
# else:<br>
# srcItem = itemParent.child(srcRow)<br>
# return srcItem.text().isnumeric()<br>
<br>
<br>
class ApplWindow(QTreeView):<br>
<br>
def __init__(self, parent=None):<br>
super().__init__(parent)<br>
self.srcModel = QStandardItemModel(parent=self)<br>
self.proxy = MyProxy(parent=self)<br>
self.proxy.setSourceModel(self.srcModel)<br>
self.setModel(self.proxy)<br>
self.expandToDepth(0)<br>
self.setHeaderHidden(True)<br>
self.setAutoExpandDelay(500)<br>
self.setSortingEnabled(True)<br>
self.fillSrcModel()<br>
self.resize(200, 500)<br>
<br>
def fillSrcModel(self):<br>
sub = {0: "x2c", 1: "694ad", 2: "t8d2x"}<br>
for idx01, c01 in enumerate("a2b"):<br>
item01 = QStandardItem(c01)<br>
for c02 in sub[idx01]:<br>
item02 = QStandardItem(c02)<br>
item01.appendRow(item02)<br>
self.srcModel.appendRow(item01)<br>
self.expandToDepth(0)<br>
<br>
def main():<br>
appl = QApplication(sys.argv)<br>
applWindow = ApplWindow()<br>
applWindow.show()<br>
return appl.exec_()<br>
<br>
<br>
if __name__ == "__main__":<br>
main()<br>
<br>
_______________________________________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br>
</blockquote></div><div><br></div><div><div style="font-family:tahoma,sans-serif" class="gmail_default">It should indeed be <span class="gmail_default" style="font-family:tahoma,sans-serif"></span><span style="font-family:courier new,monospace">itemLeft.text() < itemRight.text()</span> (for ascending order) in <span style="font-family:courier new,monospace">lessThan(self, mdlIdxSrcLeft, mdlIdxSrcRight)</span>. Yours will do descending order. I suggest you look again at your code/try a standalone test.<br></div><br></div><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><span style="font-family:tahoma,sans-serif">Kindest,</span></div><div><span style="font-family:tahoma,sans-serif">Jonathan</span></div></div></div></div></div></div>