×

Discussion Board

Results 1 to 6 of 6
  1. #1
    remy_david
    Guest

    QListView touch scroll and item selection, how to differentiale scroll and click ?

    Hello,

    I try to make a scrollable list with selectable items. The user should be able to scroll the list with a touch movment (up/down) and select a list item with a tap (i.e. just like the lists in iOS, Android and any other mobile platforms out there).

    I made the list scrollable by touch with this trick that I found here :

    Code:
    void MyListView::mouseMoveEvent ( QMouseEvent * event )
    {
        this->QListView::mouseMoveEvent(event);
        QScrollBar *scroll =  verticalScrollBar();
        scroll->setValue(scroll->value() - event->y() + y0);
        y0 = event->y();
    }
    
    void MyListView::mousePressEvent ( QMouseEvent * event )
    {
        this->QListView::mousePressEvent(event);
        y0 = event->y();
    }
    
    void MyListView::mouseReleaseEvent(QMouseEvent * event)
    {
        this->QListView::mouseReleaseEvent(event);
        y0 = -1;
    }
    However I don't manage to get the proper event for item selection.

    QListView has the following signals:
    Code:
    void	activated ( const QModelIndex & index )
    void	clicked ( const QModelIndex & index )
    void	pressed ( const QModelIndex & index )
    But they all fire when the user drag the list to scroll. IMHO clicked/pressed/activated should only occur with a tap, not with a drag. Is this a bug or a feature? How do you detect a tap ?

    As a more general comment, I seems Qt do not support touch events or is it me ? (I am not even talking about multi touch)

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: QListView touch scroll and item selection, how to differentiale scroll and click

    Quote Originally Posted by remy_david View Post
    However I don't manage to get the proper event for item selection.
    Could you please clarify what you get instead?

  3. #3
    remy_david
    Guest

    Re: QListView touch scroll and item selection, how to differentiale scroll and click

    I get item selection events (i.e. clicked/pressed/activated) both when selecting an item and when draging (i.e. scrolling) the list.
    So I cannot differentiate between click (i.e. item selection) and drag (i.e. scrolling the list).
    I want to receive a selection event ONLY when selecting an item.

  4. #4
    remy_david
    Guest

    Re: QListView touch scroll and item selection, how to differentiale scroll and click

    I try to implement the solution used by QsKineticScroller .
    But instead of using an event filter, I want to include touch management directly inside my QListView subclass. So I moved the code from the event filter directly into my overloaded event functions.
    Kinetic scrolling is working but I have a problem for detecting the click :

    Code:
    void MyListView::mouseReleaseEvent(QMouseEvent * mouseEvent)
    {    
        isPressed = false;
        // Looks like the user wanted a single click. Simulate the click,
        // as the events were already consumed
        if( !isMoving )
        {
           QMouseEvent* mousePress = new QMouseEvent(QEvent::MouseButtonPress,
              lastPressPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
           QMouseEvent* mouseRelease = new QMouseEvent(QEvent::MouseButtonRelease,
              lastPressPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    
           ignoredMouseActions = 2;
           QApplication::postEvent(this, mousePress); 
           QApplication::postEvent(this, mouseRelease);
       }
    }
    It seems those lines :
    Code:
    QApplication::postEvent(this, mousePress); 
    QApplication::postEvent(this, mouseRelease);
    have no effect when called from mouseReleaseEvent. If called from the event filter it's working.
    MyListView (aka this) never receive mousePress / mouseRelease events (i.e. mouseReleaseEvent and mousePressEvent are never called). Do you have an idea why ?
    Last edited by remy_david; 2011-02-03 at 11:31.

  5. #5
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: QListView touch scroll and item selection, how to differentiale scroll and click

    Did you try to use kinetic scroller backported to Qt 4.6-4.7 from 4.8?
    http://qt.gitorious.org/qt-labs/kine...olution/README
    Note: it's LGPL, not BSD.
    Last edited by divanov; 2011-02-03 at 12:19.

  6. #6
    remy_david
    Guest

    Re: QListView touch scroll and item selection, how to differentiale scroll and click

    Thanks, I finally found a solution and the QsKineticScroller from the wiki is under BSD which fits my needs better.
    So I replaced:

    Code:
    void MyListView::mouseReleaseEvent(QMouseEvent * mouseEvent)
    {    
        isPressed = false;
        if( !isMoving )
        {
           QMouseEvent* mousePress = new QMouseEvent(QEvent::MouseButtonPress,
              lastPressPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
           QMouseEvent* mouseRelease = new QMouseEvent(QEvent::MouseButtonRelease,
              lastPressPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    
           ignoredMouseActions = 2;
           QApplication::postEvent(this, mousePress); 
           QApplication::postEvent(this, mouseRelease);
       }
    }
    by

    Code:
    void MyListView::mouseReleaseEvent(QMouseEvent * mouseEvent)
    {    
        isPressed = false;
        if( !isMoving )
            emit(selected(indexAt(lastPressPoint)));
    }
    So instead of simulating a mouse click when the algorythm detect that the user has clicked, I emit a new signal called selected.

    I would be curious to know why postEvent was not working to simulate the mouse click in this case though.

Similar Threads

  1. how to scroll an image vertically and horizontally both in LWUIT
    By Manish_Bansal in forum Mobile Java General
    Replies: 1
    Last Post: 2010-07-13, 02:39
  2. Touch Scroll Problem
    By nisheethpandey in forum Symbian
    Replies: 0
    Last Post: 2009-11-27, 05:10
  3. Touch Scroll implementation
    By contra03 in forum Symbian
    Replies: 6
    Last Post: 2009-11-26, 11:48
  4. Replies: 5
    Last Post: 2009-11-06, 11:13

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •