Hi,

I need to use the QSortFilterProxyModel to sort strings with numbers in them, i.e. perform natural sorting.
I found this snippet online:

|import re def atoi(text): return int(text) if text.isdigit() else text def natural_keys(text): return [atoi(c) for c in re.split('(\d+)', text)] l = ['Item1', 'Item2', 'Item3', 'Item10', 'Item20'] l.sort(key=natural_keys) print l |

This works nicely but I’m wondering if it’s reliable and efficient to implement it like this in the QSortFilterProxyModel.lessThan() method?!

|def lessThan(self, source_left, source_right): natural_keys(source_left) < natural_keys(source_right) |

Any thoughts on this?

Note: I need to avoid 3rd party libraries.

Cheers,
frank

​
--

ohufxLogo 50x50 <http://www.ohufx.com>    
*vfx compositing <http://ohufx.com/compositing.html> | *workflow customisation and consulting <http://ohufx.com/customising.html>* *
                *<http://ohufx.com/compositing.html>*
<http://www.nukepedia.com/nubridge>       
        

Your gateway to over 1,000 free tools... right inside of Nuke <http://www.nukepedia.com/nubridge>

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to