Does ScrollPerPixel ever work?
-
wrote on 23 Feb 2011, 20:24 last edited by
So I have a QTreeWidget derived class that has big item height (200 pixels, for example). And I often have about 100 items in the view. I found even if I set the vertical scroll mode to ScrollPerPixel, it still scrolls too fast (or too "jumpy"). If I understand correctly, shouldn't ScrollPerPixel mean scroll pixel by pixel? I would expect the view scrolls smoothly like a static image. If I clicked on the up/down arrow buttons on the scroll bar, I expect the view to scroll up/down by one pixel. Instead, it scrolls about 180 pixels a time. How is the step size determined? Is there any way to set it to 1? I tried to obtain the vertical scrollbar and set the step size to 1, but it didn't work.
Any suggestions?
Thanks,
RP
-
wrote on 24 Feb 2011, 07:32 last edited by
No, I think you misunderstand what ScrollPerPixel means. It means that scrolling is not snapped to scroll only complete items at a time, but that you can scroll freely, meaning that only a single line of pixels might be drawn of the last or the first item.
You can adapt the step size if you want.
-
wrote on 24 Feb 2011, 16:38 last edited by
Thanks for the reply. How do I set step size? I tried to put
verticalScrollBar()->setSingleStep(..);
in the constructor or in the code where I add items to the view. Neither worked.
-
wrote on 24 Feb 2011, 16:56 last edited by
hi redhouse,
yes that should work .. I just tried something like this and it just works fine.
@
verticalScrollBar = new QScrollBar(centralWidget);
verticalScrollBar->setSingleStep(5);
@or can u paste some test code here that exactly shows the problem
-
wrote on 24 Feb 2011, 16:58 last edited by
You might have to do that after a layout change, and both the constructor and the item adding is too early for that. You can test that by simply setting it with a timer a second after setting the data or something like that.
Best solution would be to dig through the sources of QTreeView and see where/when the step size is set, so you can re-set it afterwards, of course.
-
wrote on 24 Feb 2011, 19:24 last edited by
I tried set step size in a single shot timer slot. It worked out great. Thanks for the tip.
I wish ItemView could have a explicit function to overwrite the auto step size resetting at every layout refresh.
-
wrote on 24 Feb 2011, 19:39 last edited by
With that working, you might want to see if you can find a method that you can use for this. The timer was just a trick to see if the idea worked at all :-)
-
wrote on 24 Feb 2011, 19:49 last edited by
I know, it's not perfect. It might fail if the layout took too long to refresh. But it's not critical so I can live with it. I just don't feel like diving into the Qt source code now:-|
2/8