473,805 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fast QListView numerical sort

Hi,

Using PyQt I got a QListView with about 800 entries now (but its intended to
be scalable up to about 3000).
The first column contains numerical data. Now Qt does the sorting all by its
self and quite fast enough. By default it sorts alphanumericall y, i.e. 1 10
100 101 110 111 2 ...

Solutions on the web suggested left padding the digits with white spaces
which didn't work for me.
Left padding with 0's does not look good.
Qt Manual says you can overwrite the compare method QListViewItem.c ompare -
which I did:

QListViewItem.c ompare = lambda s,a,b,c: s.text(0).toInt ()[0]
-a.text(0).toInt ()[0]

The compare method returns < 0 for "smaller", 0 for "equal", > 0 for
"bigger".
Doing so works, but causes a 2 sec delay each time a re-sort has to be done
- which is rather annoying (at only less than 1/3 of its expected load!)

Solutions I could come up with are:
a. derive a C++ QListViewItem that does the numerical sorting and use this
instead of the default QListViewItem in the hope it'll be faster
pro: probably the easyest (faster? fast enough?)
con: not portable

b. implement all sorting and inserting related functions by myself in Python
and do the sorting from Python
pro: portable
con: much more coding to be done; probably contains more bugs

Which do you favour or do you have other suggestions?

Thanks
Uwe
Jul 18 '05 #1
2 3022

"Uwe Mayer" <me*****@hadiko .de> wrote in message
news:c0******** **@news.rz.uni-karlsruhe.de...
Hi,

Using PyQt I got a QListView with about 800 entries now (but its intended to be scalable up to about 3000).
The first column contains numerical data. Now Qt does the sorting all by its self and quite fast enough. By default it sorts alphanumericall y, i.e. 1 10 100 101 110 111 2 ...

Solutions on the web suggested left padding the digits with white spaces
which didn't work for me.
Hmm, I'd expect it to work.
Left padding with 0's does not look good.
Qt Manual says you can overwrite the compare method QListViewItem.c ompare - which I did:

QListViewItem.c ompare = lambda s,a,b,c: s.text(0).toInt ()[0]
-a.text(0).toInt ()[0]

The compare method returns < 0 for "smaller", 0 for "equal", > 0 for
"bigger".
Doing so works, but causes a 2 sec delay each time a re-sort has to be done - which is rather annoying (at only less than 1/3 of its expected load!)
Well, this probably comes from PyQt's nature - its a layer between Qt
(which is C++)
and Python. QListView calls some C++ function to sort its items, which in
turn makes
a lot of calls to QListViewItem:: compare(). Every call to compare() has to
be
translated from C++ world to Python world, and the result returned back.
Solutions I could come up with are:
a. derive a C++ QListViewItem that does the numerical sorting and use this
instead of the default QListViewItem in the hope it'll be faster
pro: probably the easyest (faster? fast enough?)
con: not portable
That should be fast enough, I guess, this is the ultimate speed you can
get.
Why isn't it portable?
b. implement all sorting and inserting related functions by myself in Python and do the sorting from Python
pro: portable
con: much more coding to be done; probably contains more bugs
I'm not at all sure that it will be faster than what you currently have.
It sure might be
because you'd remove most of that translation layer calls.
Which do you favour or do you have other suggestions?

I'd say check that space-filled approach. It should work one way or
another.

Cheers,
Andy.

Jul 18 '05 #2
Andy Salnikov wrote:
The compare method returns < 0 for "smaller", 0 for "equal", > 0 for
"bigger".
Doing so works, but causes a 2 sec delay each time a re-sort has to be done
- which is rather annoying (at only less than 1/3 of its expected load!) Well, this probably comes from PyQt's nature - its a layer between Qt
(which is C++)
and Python. QListView calls some C++ function to sort its items, which in
turn makes
a lot of calls to QListViewItem:: compare(). Every call to compare() has to
be
translated from C++ world to Python world, and the result returned back.
Yes. I found another suggestion on the web: overwriting the .key() method,
which has to return the value that is to be compared during sorting.
The .key() method returns a left zero-padded string and thus the string
sorting will yield the correct results.
However, this is even slower than overwriting the .compare() method.
Solutions I could come up with are:
a. derive a C++ QListViewItem that does the numerical sorting and use
this instead of the default QListViewItem in the hope it'll be faster
pro: probably the easyest (faster? fast enough?)
con: not portable

That should be fast enough, I guess, this is the ultimate speed you can
get.
Why isn't it portable?


.... yeah, it surely will run on Windows, but then I'll have to take care of
the cross-compilation, etc. Which Windows user has a C++ compiler
installed?
Portability is surely my (personally) least problem, but working with Python
its not nice giving up this "portabilit y" feature: take the sources to
another platform - run.

Another possibility: Have you got any experience with Psyco? I just heard
about it, but didn't go into much details until now. Perhaps the
just-in-time compiler will boost the performance...

Thanks
Uwe
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
6085
by: Bob Parnes | last post by:
I cannot find a reference on identifying multiple selections in QListView. Apparently one has to iterate through all the items and test each individually, but I don't know how to do the iteration. The qt3 documentation suggests QListViewItemIterator, but this does not seem to be available in python. Thanks for any help. Bob Parnes
3
2980
by: Ali Chambers | last post by:
Hi, I have a bit of a problem with a sort procedure I need to do. I have a list of items in a listbox, eg:- 2.3%<A other text here> -4%<B other text here> 10%<C other text here> -9.3%<D other text here> 22%<E other text here>
2
1817
by: Josema | last post by:
Hi to all, I have a datagrid filled with string values, and when i click in a header column the datagrid is alphanumerical sorted , but i need sort some columns by numeric way... The datasource of this Datagrid is a DataView, that is a View of a DataTable (using the property of the datatable.CurrentView) Do you know how could i solve the sorting problem to have a numerical sort,
7
14610
by: Flavio | last post by:
Hi, I have a QListview widget that allows me to store a bunch of strings in it. This strings can be visualized, sorted, selected, etc. My Problem is that I cant find a way to get the user selected items back from it! I looked over the Qt documentation many times over but there is no method to that end. Any PyQt guru lurking around?
2
7067
by: Svenn Bjerkem | last post by:
Hi, I am looking for a bit more elaboration on the problem of deleting elements from a QListsView. I know this is a tricky problem with references, but I have not been able to extract enough knowledge from the documentation to solve a specific problem: In a dialog I have a QListView called referenceList. Entries are added and deleted from this list with buttons addButton and removeButton connected with sockets:
23
15700
by: Abhi | last post by:
Hi.. I wanted the C source code in machine readable format for the book "Numerical Recipes in C". I got hold of the pdf version of the book somehow. Does anyone have the complete C code of the book?. If yes,..can you please mail me the code or somehow share it with me?. With Regards, Abhishek S
2
7238
by: jediknight | last post by:
Hi, I have a listview which has columns of text and columns of numerical data. I need to be able to sort these columns into ascending/desending order whenever the user clicks on the column header. The text columns are sorted correctly but the numerical columns seem not to get sorted properly. For example I get the following result when I try to sort a numerical
0
1541
by: Vojta Drbohlav | last post by:
Hello, Can I get all text from first column in QListView? How? PS. Sorry for my bad English ;) Than you, Vojta
1
2177
by: Reinaldo Carvalho | last post by:
Hi, I programming with qt module and i have a qWidgetTab with a qListView inside, and i need update the qListView every 5 seconds, how do this on transparent mode to user. I do a function to update, but i dont know call then. I will start this update when user select this tab, and stop whe user leave this tab. I need a thread ot something else?
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10614
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.