Results 1 to 2 of 2

Thread: [SOLVED]Scrolling through ScrollView with keys

  1. #1
    Join Date
    Jun 2015
    Posts
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default [SOLVED]Scrolling through ScrollView with keys

    Hi,

    I am trying to create a scroll area which I can scroll up and down through using arrow keys. I have been able to scroll using the mouse, but not the keyboard. Any help would be appreciated.

    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Window 2.2
    3. import QtQuick.Controls 1.2
    4. import custom.sdk 1.0
    5.  
    6. Window {
    7. width: 1280
    8. height: 720
    9. visible: true
    10.  
    11. Rectangle{
    12. anchors.fill: parent
    13. color: "#021d3a"
    14. ScrollView{
    15. x: 100
    16. y: 100
    17. width: 1080
    18. height:600
    19. focus:true
    20. contentItem: Text{
    21. width:1000
    22. wrapMode: Text.WordWrap
    23. color: "white"
    24. font.family:"LatoRegular"
    25. font.pointSize: 20
    26. text:"Test\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\nTest\n"
    27. }
    28. }
    29. }
    30. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by TristanV; 22nd June 2015 at 23:36.

  2. #2
    Join Date
    Jun 2015
    Posts
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Scrolling through ScrollView with keys

    After more digging, I found that Flickable was the way to go.

    Qt Code:
    1. Flickable {
    2. id: testFlick
    3. boundsBehavior: Flickable.StopAtBounds
    4. clip:true
    5. x:100
    6. y:100
    7. width:200
    8. height:200
    9. contentWidth: 500
    10. contentHeight: textBox.paintedHeight
    11. focus:true
    12. Keys.onPressed: {
    13. console.log("keypress registered")
    14. if(event.key == Qt.Key_Down){
    15. testFlick.flick(0,-500);
    16. }
    17. else if(event.key == Qt.Key_Up){
    18. testFlick.flick(0,500);
    19. }
    20. }
    21.  
    22. Text{
    23. id: textBox
    24. font.pointSize: 20
    25. text: "test\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\n";
    26. }
    27. }
    28. Rectangle{
    29. id: scrollbarBackground
    30. anchors.right: testFlick.right
    31. z: 1
    32. width:10
    33. y: testFlick.y
    34. height: testFlick.height
    35. color: "brown"
    36. }
    37.  
    38. Rectangle {
    39. id: scrollbar
    40. anchors.right: testFlick.right
    41. y:testFlick.visibleArea.yPosition * testFlick.height + testFlick.y
    42. z: 2
    43. width: 10
    44. height: testFlick.visibleArea.heightRatio * testFlick.height
    45. color: "black"
    46. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Disable QGraphicsView scrolling with arrow keys
    By sakya in forum Qt Programming
    Replies: 0
    Last Post: 9th September 2013, 11:45
  2. Replies: 0
    Last Post: 7th July 2013, 02:43
  3. Overriding ScrollView onWheel()
    By oberlus in forum Qt Quick
    Replies: 0
    Last Post: 4th June 2013, 17:36
  4. implementing 'scrollview'
    By rishiraj in forum Newbie
    Replies: 1
    Last Post: 18th December 2008, 12:23
  5. filling scrollview
    By illuzioner in forum Qt Programming
    Replies: 1
    Last Post: 17th February 2006, 22:00

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.