LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-13-2005, 05:53 AM   #1
shivaligupta
Member
 
Registered: Oct 2004
Posts: 45

Rep: Reputation: 15
QListview in Qt


I want that as the user enters a record it should be appended at the end
where as right now i have turned the sorting off by using setSorting() & it is adding the record at the beginning & if i set sorting on then 1,2,3,4,5,6,7,8,9,10 are sorted as 1,10,2,3,4... means that it interprets them as characters. I want to sort them as integers.

Thanks in advance
 
Old 01-13-2005, 03:19 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,408

Rep: Reputation: 108Reputation: 108
You need to overload QListViewItem::compare method. It means you need to add a new class for list elements with parent QListViewItem and write your version of the compare function.

From Qt Assistant:
Quote:
int QListViewItem::compare ( QListViewItem * i, int col, bool ascending ) const [virtual]
Compares this list view item to i using the column col in ascending order. Returns -1 if this item is less than i, 0 if they are equal and 1 if this item is greater than i.
This function is used for sorting.
The default implementation compares the item keys (key()) using QString::localeAwareCompare(). A reimplementation can use different values and a different comparison function. Here is a reimplementation that uses plain Unicode comparison:
Code:
    int MyListViewItem::compare( QListViewItem *i, int col,
                                 bool ascending ) const
    {
        return key( col, ascending ).compare( i->key( col, ascending) );
    }
We don't recommend using ascending so your code can safely ignore it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
QListView help elvislu Programming 2 05-17-2005 09:37 AM
how to connect my signal with standart (Qt(QListView)) stpg Programming 1 07-05-2004 07:22 AM


All times are GMT -5. The time now is 02:57 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration