Qt-interest Archive, March 2002
Re: QlistView and setCurrentItem problem (qt bug ?) (fwd)
Message 1 in thread
Hi all,
i'm sorry, i forgot to cc to the list. Greger answered me he had not the
problem, does anyone here has the same problem or an idea from where
it comes ? may be compiler or something else, i don't understand.
regards
---------- Forwarded message ----------
Date: Sat, 16 Mar 2002 18:37:15 +0100 (CET)
From: acabiran@club-internet.fr
To: Greger Haga <gregerhaga@yahoo.com>
Subject: Re: QlistView and setCurrentItem problem (qt bug ?)
Hi Greger,
when i run the example, the selected item (the last one), is not visible,
i see elements 0 1 2 and 3 but i selected 9. Does the behaviour
is the same when you run it ? And if yes, is it the wanted behaviour ?
I lightly modified the example by using firstChild and nextSibling to
select the last item and compile it with qt 2, the result is identical.
regards,
=====================================================
Alain Cabiran <acabiran@club-internet.fr>
A Greger Haga pour le message du 15.03.2002 à 18:14 (+0200)
> acabiran@club-internet.fr wrote:
>
> > Hi all,
> >
> > when i call QListView.setCurrentItem with an invisible item, the item
> > becomes the current but it remains invisible. (i.e. i have to call
> > ensureItemVisible). Is this normal ? an example is joined (qt 3.0.2).
>
> Your attached example creates ten items in the listview, what do you exactly
> mean?
> /G
Message 2 in thread
acabiran@club-internet.fr wrote:
>Hi all,
>
>i'm sorry, i forgot to cc to the list. Greger answered me he had not the
>problem, does anyone here has the same problem or an idea from where
>it comes ? may be compiler or something else, i don't understand.
I have also found that since I moved to Qt3[1]
QListView::ensureItemVisible "misses" in some lists whereas it used to
work fine with all.
In very short lists only a few times longer that the visible area it
seems to work, but in relatively longer lists it is now regularly "off
by one" with the desired item being just below the visible area of the
list - a single [Down] cursor key reveals both the original target of
ensureItemVisible and the line below it. :(
[1] Currently using Qt 3.0.2 with MSCV++ 6 & Win2K.
--
[ signature omitted ]
Message 3 in thread
Also sent to qt-bugs
David Wright <David.Wright@skyewright.co.uk> wrote:
>acabiran@club-internet.fr wrote:
>>Hi all,
>>
>>i'm sorry, i forgot to cc to the list. Greger answered me he had not
the
>>problem, does anyone here has the same problem or an idea from where
>>it comes ? may be compiler or something else, i don't understand.
>
>I have also found that since I moved to Qt3[1]
>QListView::ensureItemVisible "misses" in some lists whereas it used to
>work fine with all.
>
>In very short lists only a few times longer that the visible area it
>seems to work, but in relatively longer lists it is now regularly "off
>by one" with the desired item being just below the visible area of the
>list - a single [Down] cursor key reveals both the original target of
>ensureItemVisible and the line below it. :(
>
>[1] Currently using Qt 3.0.2 with MSCV++ 6 & Win2K.
I've been doing some further study on this. Though I don't understand
the root cause, I have some more information and have observed a
possible anomaly and have developed a partial workaround.
Firstly, the problem seems to be specific to some versions of Windows.
Using the same application, the same build of Qt and the same list
contents on WinNT4 & Win2K, QListView::ensureItemVisible results in a
visible item on the WinNT4 system but not on the Win2K.
Even on the Win2K system the "miss" is only apparent the first time
QListView::ensureItemVisible is used with a given list.
Tracing through QListView::ensureItemVisible on Win2K I have found that
on the first occasion that QListView::ensureItemVisible is called
visibleHeight() returns a higher value than on subsequent calls. The
value on the subsequent calls seems to be the correct one and the
difference is enough that on the first call the desired item is just off
the bottom of the viewport.
I can't figure out at what point the visibleHeight() is changing, so I'm
not sure of the real cause. Some initialisation effect seems likely.
My workaround has been to hack the QListView::ensureItemVisible
positioning logic to put the desired item further up the viewport and so
clear of the error.
In Qt 3.0.3 at qlistview.cpp line 6046 I have replaced
if ( isVisible() && y + h > contentsY() + visibleHeight() )
setContentsPos( contentsX(), y - visibleHeight() + h );
with
if ( isVisible() && y - (visibleHeight() / 2) > contentsY() )
setContentsPos( contentsX(), y - (visibleHeight() / 2));
The workaround is only partial because the position moderation performed
in QScrollView::moveContents by the lines
if ( -y+visibleHeight() > contentsHeight() )
y=QMIN(0,-contentsHeight()+visibleHeight());
mean that for the last few items on the list the over large
visibleHeight() again pushes the desired item out of sight. :(
If anyone has the real answer to the problem, or can spot a fundamental
fault with my temporary workaround I be very interested to hear.
Incidentally, as well as being a partial workaround for the problem, I
prefer the effect produced by the revised code (which aims to put the
desired item in the middle of the viewport) where it does work because
it means that there are usually some items visible below the desired
item too - giving more context.
--
[ signature omitted ]