Qt-interest Archive, March 2002
Moving items up/down a QListView (again)
Message 1 in thread
I got help on this before, but for some reason (bug?) I can't move items
up... I've got tow arrow-up/arrow-down buttons on the left of a QListView
like this, and I've connected the following slots to the clicked signal of
the buttons:
void
DataManipulatorDialog::SlotMoveManipulatorUp()
{
QListViewItem* item = lvManipList -> selectedItem();
if (!item)
{
return;
}
else
{
if (item -> itemAbove() == NULL)
{
return;
}
item -> moveItem(item -> itemAbove());
}
}
void
DataManipulatorDialog::SlotMoveManipulatorDown()
{
QListViewItem* item = lvManipList -> selectedItem();
if (!item)
{
return;
}
else
{
if (item -> itemBelow() == NULL)
{
return;
}
item -> moveItem(item -> itemBelow());
}
}
Moving an item down the list works just as expected, but when I'm trying
to move up, exactly nothing happens. I've stepped through both functions,
and they both behave as expected, i.e. the "move up" function does not
return because of some nullpointer - moveItem _is_ called correctly as in
"move down".
None of my QListViewItem's have children if that matters.
My guess is that this is a Qt bug.
Cheers,
--
[ signature omitted ]
Message 2 in thread
- Subject: Re: Moving items up/down a QListView (again)
- From: Arne Heizmann <arne@xxxxxxxxx>
- Date: Fri, 01 Mar 2002 15:19:21 +0100
- Organization: ZN Vision Technologies AG
- To: qt-interest@xxxxxxxxxxxxx
Tarjei Knapstad schrieb:
>
> I got help on this before, but for some reason (bug?) I can't move items
> up... I've got tow arrow-up/arrow-down buttons on the left of a QListView
> like this, and I've connected the following slots to the clicked signal of
> the buttons:
>
> item -> moveItem(item -> itemAbove());
You told it to move the item underneath the item above it. This call is
perfectly right in not doing anything ;-)
Instead, use:
item -> itemAbove() -> moveItem ( item );
Problem solved ;-)
Message 3 in thread
> I got help on this before, but for some reason (bug?) I can't
> move items
> up... I've got tow arrow-up/arrow-down buttons on the left of
> a QListView
> like this, and I've connected the following slots to the
> clicked signal of
> the buttons:
>
> void
> DataManipulatorDialog::SlotMoveManipulatorUp()
> {
> QListViewItem* item = lvManipList -> selectedItem();
> if (!item)
> {
> return;
> }
> else
> {
> if (item -> itemAbove() == NULL)
> {
> return;
> }
> item -> moveItem(item -> itemAbove());
> }
> }
>
moveItem(QListViewItem *after) moves the calling item to a position
after the QListViewItem passed as argument.
So item->moveItem(item->itemAbove());
moves item to a position it's already at.
Something like (however ugly):
item->itemAbove()->moveItem(item);
might do it
> My guess is that this is a Qt bug.
I guess not...
--
[ signature omitted ]
Message 4 in thread
On Fri, 1 Mar 2002, Eriksson Torbjörn wrote:
> moveItem(QListViewItem *after) moves the calling item to a position
> after the QListViewItem passed as argument.
>
> So item->moveItem(item->itemAbove());
> moves item to a position it's already at.
>
Ah, I see.
> Something like (however ugly):
> item->itemAbove()->moveItem(item);
> might do it
>
Well, a bit hard to read, but should be safe as long as none of the
pointers are null (which I check for anyhow...)
> > My guess is that this is a Qt bug.
>
> I guess not...
:)
Thanks,
--
[ signature omitted ]