QScrollArea - how to enable touch interactions to scroll to next item?

7.7k views Asked by At

I'm using the Nokia Qt SDK and designed a small banner carousel in the top area. It looks like this:

UI demo

The hierarchy looks like:

UI hierarchy

After installing this in the emulator, I try to make it scrollable (flinging). It's a simple task I would guess (like ScrollView in Android, or UIScrollView in iOS), but so far no joy. All links in the internet point me of custom scroll implementations etc etc. which I don't want to do nor expect to do as Qt should be a higher level framework? What is the state of the art here? ;-)

Question in short: How can I make this QScrollArea respond to touch (fling, scroll, drag etc) events and reveal the other widgets in the queue? I'm not expecting it to be able to "snap" into a child widget (which is another requirement later ;)).

2

There are 2 answers

3
frozenkoi On BEST ANSWER

Take a look at Flickable (at http://blog.qt.io/blog/2009/07/19/kinetic-scrolling-on-any-widgets/) and FlickCharm (linked to from that first address ) either to have an idea on how to implement it on your own or use it as is.

Note that it might not be necessary if your target is Maemo, as its Qt port handles it.

3
Daniel Gallagher On

Have you tried enabling gestures? I haven't used the gesture support yet, but it looks like it's as easy as

scrollEvents->grabGesture(Qt::SwipeGesture);
// or...
scrollEvents->grabGesture(Qt::PanGesture);

I don't know if QScrollArea already handles gestures, so if that doesn't work, you may need to sub-class QScrollArea and override the event method to handle gesture events, as described in the Gestures Programming Guide.