Sorting in QListView class
Hi guys,
How can i disable sorting of QListView class if i want the items to be placed in the ListView as they are.???
For example-
Code:
dir.
setSorting(QDir::DirsFirst);
const QFileInfoList *dirList=dir.entryInfoList();
QFileInfoListIterator it(dirList);
while(fi=it.current())
{
QListVIewItem *dirItem=new QListViewItem(ListView);
dirItem->setText(0,fi->fileName());
ListView->insertItem(dirItem);
++it;
}
In this case the items which i want to show are file/folder items which i already sort in QDir class setSorting option. Now i don't want ListView to resort the items according to ascending or descending order..
QListView class gives sorting option as QListView::setSorting(int,bool ascending=True);
if i set int(column)=-1 the sorting is disabled but the items are always viewed in reverse order. where as i want my items to be viewed as Directories first and FIles later. Plz guide!!!
Re: Sorting in QListView class
You can add items to the list in reverse order or reimplement QListView::sort() to perform sorting according to the rules you want.
Re: Sorting in QListView class
Quote:
where as i want my items to be viewed as Directories first and FIles later.
That itself implies you want custom sort ;)
Re: Sorting in QListView class
But my list is already sorted using QDir::DIrsFirst;
Once the dir.entryInfoList is sorted. the iterator it reads the fileName and assigns the item name respectively. Its just that QListView again resorts the items ascending or descending by name precedence. I just want to switch off QListView class's sorting option which it does default.
As Wysota suggested, i need to reimplement the QListView::sort() method....
What parameters should i reimplement...the code for implementation of QListView class is too big....to read and understand easily for me!!!Any simpler way???
Re: Sorting in QListView class
Quote:
Originally Posted by
Yayati.Ekbote
As Wysota suggested, i need to reimplement the QListView::sort() method....
What parameters should i reimplement...the code for implementation of QListView class is too big....to read and understand easily for me!!!Any simpler way???
I'd try to leave the implementation of sort() empty, you shouldn't have any sorting at all then. But I looked at your code again and I think the problem is not with sorting but with the fact that you are inserting items to the beginning of the list instead of the end of the list. There is a QListViewItem constructor that lets you specify where to insert the item.
Re: Sorting in QListView class
Thanks, I got the problem. Ya i was inserting items at the beginning. I realized that and made the following change.
QListViewItem *dirItem=new QListViewItem(ListView,dirItem);
i.e. i inserted items after the dirItem..
Thanks very much.