SCrolling QTextEdit with touch screen

1,911 views
Skip to first unread message

S.H.H

unread,
Sep 1, 2012, 10:14:53 AM9/1/12
to andro...@googlegroups.com
hi my friends

i have problem for SCrolling QTextEdit  in touch screen..
how can i scroll textedit as normal ?

 

Peter Bočan

unread,
Sep 2, 2012, 5:04:01 PM9/2/12
to andro...@googlegroups.com
What do you mean "as normal" ? I would use swipe gesture or some scroll bar...

Dňa sobota, 1. septembra 2012 16:14:53 UTC+2 S.H.H napísal(-a):

S.H.H

unread,
Sep 22, 2012, 1:37:32 PM9/22/12
to andro...@googlegroups.com


What do you mean "as normal"

for  scorolling in textedit or any other widget i most to touch with two finger to move up or down and its not  normal
scroll bar  works but i think swipe gesture is better..
plase help me or some examle for using swipe gesture

Regards

freekee1

unread,
Sep 22, 2012, 1:41:12 PM9/22/12
to andro...@googlegroups.com
we use the pan gesture in a flick scroller class similar to this one http://blog.qt.digia.com/2008/11/15/flick-list-or-kinetic-scrolling/.
just be aware that the default Qt gesture recognizers recognize pan only with 2 fingers, swipe with 3 fingers i think ... so you might need to write your own recognizer.
there are quite some examples of custom Qt gesture recognizers though, so that shouldn't be too hard to figure out.

kind regards

S.H.H

unread,
Sep 23, 2012, 12:43:07 PM9/23/12
to andro...@googlegroups.com
thanks

i use FlickCharm class from  anomaly in qt examples 
 it works good ..

just one problem is not solved yet
i need long-press event ...

kind regards

freekee1

unread,
Sep 23, 2012, 12:50:02 PM9/23/12
to andro...@googlegroups.com
if i remember correctly, the tap and hold gesture works out of the box on android, doesn't it?
so you'd basically have to do grabGesture(Qt::TapAndHoldGesture) in the widget to grab it, then
bool TheWidget::event(QEvent *e)
{
    if(e->type() == QEvent::Gesture)
    {
        QGestureEvent *ge = static_cast<QGestureEvent*>(e);
        QTapAndHoldGesture *g = static_cast<QTapAndHoldGesture*>(ge->gesture(Qt::TapAndHoldGesture));
        if(g != NULL)
        {
            return onTapAndHoldGesture(g);
        }
    }
    // [...]
    return QWidget::event(e);
}

then you can do whatever you want to do in onTapAndHoldGestre(QTapAndHoldGesture*).

sorry if there are any mistakes in there, it might not be copy&pastable but that's roughly how it can be done.
maybe you need to check for (g->state == Qt::GestureFinished) in onTapAndHoldGesture, too.
just try it out and read the docs and ask google, it's not hard.


hope that helps.

kind regards

Marco Bernasocchi

unread,
Sep 23, 2012, 12:54:37 PM9/23/12
to andro...@googlegroups.com

yes it is the way it works. just fyi, bogdan just pushed a fix in beta 2 that triggers right click on longpress
ciao

Marco Bernasocchi (mobile)
http://opengis.ch

S.H.H

unread,
Sep 24, 2012, 9:57:39 PM9/24/12
to andro...@googlegroups.com
thanks...

i used this code :

class MyListWidget : public QListWidget
{
   Q_OBJECT
    public:
    explicit MyListWidget(QWidget *parent=0)
        :QListWidget(parent)
    {
        setAttribute(Qt::WA_AcceptTouchEvents);     
        grabGesture(Qt::SwipeGesture);
    }
    bool event(QEvent *event)
    {
        if (event->type() == QEvent::Gesture)
            return gestureEvent(static_cast<QGestureEvent*>(event));
        return QWidget::event(event);
    }
    bool gestureEvent(QGestureEvent *event)
    {
        qDebug()<< "QGestureEvent";
        if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
            swipeTriggered(static_cast<QSwipeGesture *>(swipe));
        else{
       QTapAndHoldGesture *tapAndHold = static_cast<QTapAndHoldGesture*>(event->gesture(Qt::TapAndHoldGesture));
               if(tapAndHold != NULL)
                    onTapAndHoldGesture(tapAndHold);
           }
        return true;
    }
    void onTapAndHoldGesture(QTapAndHoldGesture *gesture)
    {
        qDebug()<< "QTapAndHoldGesture";
    }
    void swipeTriggered(QSwipeGesture *gesture)
    {
        qDebug()<< "SwipeGesture";
    }
};

but do not works...
please help me

noname

unread,
Sep 25, 2012, 2:31:50 AM9/25/12
to andro...@googlegroups.com
so it doesn't work ... well, that is very little information. try to
describe the problem in some more detail next time.
what i can see from the code:
1. you don't grab Qt::TapAndHoldGesture
2. you use QSwipeGesture - have you written a gesture recognizer for
swipe or do you use it with three fingers (or maybe it's fixed in Qt,
since i don't use the latest version)?
i don't know what the issue is exactly, so i don't know if that helps or
you knew that already ...


kind regards

S.H.H

unread,
Sep 25, 2012, 1:30:56 PM9/25/12
to andro...@googlegroups.com

1. you don't grab Qt::TapAndHoldGesture
2. you use QSwipeGesture - have you written a gesture recognizer for

first all sorry for my bad English

i don't need QSwipeGesture howaver..

i just need long-press event ..
for example when i long press appear a massage box
i used this code and i did't saw massage box :


class MyListWidget : public QListWidget
{
   Q_OBJECT
    public:
    explicit MyListWidget(QWidget *parent=0)
        :QListWidget(parent)
    {
        setAttribute(Qt::WA_AcceptTouchEvents);     
    }

    bool event(QEvent *event)
    {
        if (event->type() == QEvent::Gesture)
            return gestureEvent(static_cast<QGestureEvent*>(event));
        return QWidget::event(event);
    }
    bool gestureEvent(QGestureEvent *event)
    {
     
       QTapAndHoldGesture *tapAndHold = static_cast<QTapAndHoldGesture*>(event->gesture(Qt::TapAndHoldGesture));
               if(tapAndHold != NULL)
                    onTapAndHoldGesture(tapAndHold);
          
        return true;
    }
    void onTapAndHoldGesture(QTapAndHoldGesture *gesture)
    {
      QMessageBox::about(0,"long press","");
    }

Marco Bernasocchi

unread,
Sep 25, 2012, 8:33:33 PM9/25/12
to andro...@googlegroups.com

Marco Bernasocchi (mobile)
http://opengis.ch

On Sep 26, 2012 12:30 AM, "S.H.H" <etra...@gmail.com> wrote:
>
>
>> 1. you don't grab Qt::TapAndHoldGesture

here is the answer already? you have to grab the gesture.

S.H.H

unread,
Sep 27, 2012, 1:21:15 AM9/27/12
to andro...@googlegroups.com
how can i grab the gesture

please give a full example

Marco Bernasocchi

unread,
Sep 27, 2012, 2:34:23 AM9/27/12
to andro...@googlegroups.com

how about doing the homeworks and ask google?

http://www.google.com/search?q=grab+qt+gesture
http://qt-project.org/doc/qt-4.8/gestures-overview.html

Marco Bernasocchi (mobile)
http://opengis.ch

Reply all
Reply to author
Forward
0 new messages