Results 1 to 5 of 5

Thread: Scrolling using QScroller class ..

  1. #1
    Join Date
    May 2010
    Posts
    19
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Scrolling using QScroller class ..

    I'm trying to get kinetic scroll on a widget using Qt 5.1's QScroller class but it does not work when i use "TouchGesture" when deployed to device. The "LeftMouseButtonGesture" gesturetype works properly on desktop as well as the android device. I'm unsure whether my code is correct or wrong.

    Following is my code:

    Qt Code:
    1. Dialog::Dialog(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::Dialog)
    4. {
    5. ui->setupUi(this);
    6. resize(800,480);
    7.  
    8. QScrollArea *scroll = new QScrollArea(this);
    9. scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    10. scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    11.  
    12. QWidget *viewport = new QWidget(this);
    13. scroll->setWidget(viewport);
    14. scroll->setWidgetResizable(true);
    15.  
    16. QVBoxLayout *l = new QVBoxLayout(viewport);
    17. viewport->setLayout(l);
    18.  
    19. for(int i = 0; i < 100; i++)
    20. {
    21. QLabel *lb = new QLabel();
    22. lb->setText("Label "+QString::number(i));
    23. lb->setStyleSheet("border-radius: 5px;"
    24. "color: #FAFAFA;"
    25. "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
    26. "stop: 0 #a6a6a6, stop: 0.08 #7f7f7f,"
    27. "stop: 0.39999 #717171, stop: 0.4 #626262,"
    28. "stop: 0.9 #4c4c4c, stop: 1 #333333);"
    29. );
    30. l->addWidget(lb);
    31. }
    32.  
    33. QVBoxLayout *dialog_layout = new QVBoxLayout(this);
    34. dialog_layout->addWidget(scroll); // add scroll to the QDialog's layout
    35. setLayout(dialog_layout);
    36. show();
    37.  
    38. QScroller::grabGesture(scroll, QScroller::TouchGesture); //Replace TouchGesture with LeftMouseButtonGesture and it works flawlessly
    39. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Scrolling using QScroller class ..

    Why you want to write a custom code for kinetic scroll?

    You can use FlickCharm for the same.
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

  3. #3
    Join Date
    May 2010
    Posts
    19
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Scrolling using QScroller class ..

    I'm not using custom scroll. Its a new class provided by Qt 5 which enables kinectic scroll on the scroll areas. Previously in Qt 4 i has used FlickCharm for this purpose.
    Now since i'm migrating my application to Qt5 i thought of giving it a try.
    Well my observation about QScroller is:
    1. QScroller works when using the QScroller::LeftMouseButtonGesture on QScrollArea on touch devices and desktop
    2. QScroller works using QScroller::LeftMouseButtonGesture and QScroller::TouchGesture on QListViews/treeviews on touch devices and desktop
    3. QScroller doesnot work on QScrollArea when QScroller::TouchGesture is used for touch devices.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Scrolling using QScroller class ..

    Quote Originally Posted by p3c0 View Post
    I'm trying to get kinetic scroll on a widget using Qt 5.1's QScroller class but it does not work when i use "TouchGesture" when deployed to device.
    Does the gesture itself work? Note that it requires multi-touch as opposed to just using the "mouse".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5

    Default Re: Scrolling using QScroller class ..

    You are right! It is exactly what I notice. I just used the
    QScroller::LeftMouseButtonGesture in my application and it's working for desktop and android. However it isn't smooth but it's other issue.
    Quote Originally Posted by p3c0 View Post
    I'm not using custom scroll. Its a new class provided by Qt 5 which enables kinectic scroll on the scroll areas. Previously in Qt 4 i has used FlickCharm for this purpose.
    Now since i'm migrating my application to Qt5 i thought of giving it a try.
    Well my observation about QScroller is:
    1. QScroller works when using the QScroller::LeftMouseButtonGesture on QScrollArea on touch devices and desktop
    2. QScroller works using QScroller::LeftMouseButtonGesture and QScroller::TouchGesture on QListViews/treeviews on touch devices and desktop
    3. QScroller doesnot work on QScrollArea when QScroller::TouchGesture is used for touch devices.

Similar Threads

  1. show object (scene) in widget in class class mainwindow
    By rimie23 in forum Qt Programming
    Replies: 8
    Last Post: 1st May 2012, 16:15
  2. Replies: 1
    Last Post: 20th January 2012, 04:39
  3. Replies: 7
    Last Post: 18th August 2011, 14:43
  4. Replies: 3
    Last Post: 27th December 2008, 19:34
  5. Replies: 3
    Last Post: 16th May 2007, 11:07

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.