Qt-interest Archive, September 2002
Ordinal count in QListView
Message 1 in thread
Hello.
I'm looking for a convenient way to know the ordinal index of a
QListViewItem within a QListView.
For instance, when I click on the 3rd line, I know which QListViewItem has
been selected, but I want to know it's index.
This question as already been asked there, but the "asker" (Spell ?)
answered himself that the question was stupid.. ;)
I currently use a combination of 'QListView::itemPos()',
'QListViewItem::height()', and 'QListView::selectedItem()', but this looks
like a bad trick.
I presume that I can go through the QListViewItem collection with a
firstChild() and some nextSibling() to find out this, but something like an
:
"int QListView::itemIndex(QListViewItem *)" function is welcome.
(the same in the other way, to access directly to the xxth QListViewItem :
"QListViewItem * QListView::itemAtIndex(int)" function )
Does Anybody have any idea ?
---
Pierre-Nicolas RIGAL - pnr@4js.com
Four J's Development Tools - www.fourjs.com
Tel +33 (0)3 88 18 61 20 - Fax +33 (0)3 88 18 61 21
Message 2 in thread
Hi !
This function returns the y-coordinate of the item.
For instance, if the height of my QListViewItems is "16", the result of this
function will be ( 16 x ordinal_position).
I currently use this function like this:
QListView *myList;
QListViewItem *currentItem;
return myList->itemPos(currentItem) / currentItem->height();
which works (and returns 0 for first item as you said), but I was expected
something more elegant ;), for instance something similar as in Visual
Basic, with the:
list.item(position as integer)
and
list.selectedIndex() as integer
functions or something like that. I have some doubt about my solution
because of this doc's remark:
(itemPos)
"This function is normally much slower than itemAt() but it works for all
items, whereas itemAt() normally works only for items on the screen."
Thank you for your answer.
> -----Original Message-----
> From: Joe Butith [mailto:carsten@fieguth.de]
> Sent: jeudi 5 septembre 2002 19:15
> To: pnr@4js.com
> Subject: Re: Ordinal count in QListView
>
>
> Have a look at this:
>
> file:///C:/Programme/qt/3.0.5/doc/html/qlistview.html#itemPos
>
> itemPos ( listView->selectedItem() )
>
> Pay attention that the first item of the listView have the position 0, of
> course....
>
> Have luck,
>
>
> Joe
>
>
> At 18:30 05.09.02 +0200, you wrote:
> >Hello.
> >I'm looking for a convenient way to know the ordinal index of a
> >QListViewItem within a QListView.
> >
> >For instance, when I click on the 3rd line, I know which
> QListViewItem has
> >been selected, but I want to know it's index.
> >
> >This question as already been asked there, but the "asker" (Spell ?)
> >answered himself that the question was stupid.. ;)
> >
> >I currently use a combination of 'QListView::itemPos()',
> >'QListViewItem::height()', and 'QListView::selectedItem()', but
> this looks
> >like a bad trick.
> >
> >I presume that I can go through the QListViewItem collection with a
> >firstChild() and some nextSibling() to find out this, but
> something like an
> >:
> >"int QListView::itemIndex(QListViewItem *)" function is welcome.
> >
> >(the same in the other way, to access directly to the xxth
> QListViewItem :
> >"QListViewItem * QListView::itemAtIndex(int)" function )
> >
> >Does Anybody have any idea ?
> >
> >
> >---
> >Pierre-Nicolas RIGAL - pnr@4js.com
> >Four J's Development Tools - www.fourjs.com
> >Tel +33 (0)3 88 18 61 20 - Fax +33 (0)3 88 18 61 21
> >
> >--
> >List archive and information: http://lists.trolltech.com/qt-interest/
>
>
> ==============================
> schaut doch mal unter
> http://carsten.fieguth.de
> vorbei.
> Witziges, Privates, Fantasy und mehr....
Message 3 in thread
You could subclass QListViewItem:
class SelectionItem : public QListViewItem {
public:
SelectionItem(QListView *parent,QString label,int ID)
: QListViewItem(parent,label)
{ id = ID;}
SelectionItem(QListViewItem *parent,QString label,int ID)
: QListViewItem(parent,label)
{ id = ID;}
int getId()
{ return id;};
protected:
int id;
};
Then you'll need to cast the return value of functions that give you a
QListViewItem:
QListView *view;
SelectionItem *item = (SelectionItem*) view->firstChild();
int Id = item->getId();
William R Volz, Senior Research Geophysicist
ChevronTexaco
Exploration & Production Technology Company
Subsurface Characterization Business Line
Interpretation Product Development & Support
4800 Fournace Place, Bellaire, TX, 77401
Tel 713 432 6666 CTN 666 6666 Fax 713 432 2536
><mailto:wrvo@chevrontexaco.com>
>This message may contain confidential information that is proprietary to
ChevronTexaco and is intended only for the use of the parties to whom it is
addressed. If you are not an intended recipient, you are hereby notified
that any disclosure, copying, distribution or use of any information in this
message is strictly prohibited. If you have received this message in error,
please notify me immediately at the telephone number noted above.
-----Original Message-----
From: Pierre-Nicolas RIGAL [mailto:pnr@4js.com]
Sent: Thursday, September 05, 2002 11:31 AM
To: Qt-Interest@Trolltech. Com
Subject: Ordinal count in QListView
Hello.
I'm looking for a convenient way to know the ordinal index of a
QListViewItem within a QListView.
For instance, when I click on the 3rd line, I know which QListViewItem has
been selected, but I want to know it's index.
This question as already been asked there, but the "asker" (Spell ?)
answered himself that the question was stupid.. ;)
I currently use a combination of 'QListView::itemPos()',
'QListViewItem::height()', and 'QListView::selectedItem()', but this looks
like a bad trick.
I presume that I can go through the QListViewItem collection with a
firstChild() and some nextSibling() to find out this, but something like an
:
"int QListView::itemIndex(QListViewItem *)" function is welcome.
(the same in the other way, to access directly to the xxth QListViewItem :
"QListViewItem * QListView::itemAtIndex(int)" function )
Does Anybody have any idea ?
---
Pierre-Nicolas RIGAL - pnr@4js.com
Four J's Development Tools - www.fourjs.com
Tel +33 (0)3 88 18 61 20 - Fax +33 (0)3 88 18 61 21
--
[ signature omitted ]