Results 1 to 3 of 3

Thread: Overriding ScrollView onWheel()

  1. #1
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Overriding ScrollView onWheel()

    Hi,

    I have an Image loaded in a ScrollView and I have attempted to override the ScrollView onWheel behaviour as follows:


    Qt Code:
    1. import QtQuick 2.1
    2. import QtQuick.Controls 1.0
    3.  
    4. Rectangle {
    5. id: root
    6. color: "grey"
    7.  
    8. ScrollView {
    9. id: scrollview
    10. frameVisible: false
    11. anchors.fill: parent
    12.  
    13. Image {
    14. source: "qrc:/images/sample.jpg"
    15.  
    16. MouseArea {
    17. anchors.fill: parent
    18. onClicked: {
    19. console.log("onClicked")
    20. }
    21.  
    22. onWheel: {
    23. console.log("onWheel")
    24. }
    25. }
    26. }
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 

    When run if I click on the image the onClicked() is called ok, but if I move the mouse wheel the onWheel is never called.

    What am I doing wrong?

    Eventually (if I can get it to work) I would like to override it in such a way that moving the mouse wheel while holding the control key down calls some application specific code. Moving the wheel without holding the control key should allow the ScrollView to move the scrollbar. Something like:

    Qt Code:
    1. onWheel: {
    2. console.log("onWheel")
    3. if (wheel.modifiers & Qt.ControlModifier)
    4. doSomething(wheel)
    5. else
    6. how_do_I_call_the_normal_behaviour?
    7. }
    To copy to clipboard, switch view to plain text mode 

    2. Any ideas on how to call the default behaviour? Is there a way to not consume the event so that the parent can do so?

    Thanks for any help

  2. #2
    Join Date
    Mar 2012
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Overriding ScrollView onWheel()

    Hi oberlus,
    did you solve your problem? I work on the same issue.
    I saw that onPressed and onReleased are working, but this doesn't help.
    Greetings,
    Lamb

  3. #3
    Join Date
    Mar 2012
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Overriding ScrollView onWheel()

    Hi oberlus,

    I found a similar solution which is based on
    http://harmattan-dev.nokia.com/docs/...scrollbar.html



    In this qml code the scrollbars will be painted with rectangles and not with ScrollView. The mouse wheel can zoom in and out and with the left mouse it is possible to move the image (comes from Flickable).
    Please note the „clip: true“ property which is from my side important because around the „detailImageRect“ are gui elements which must not be overlayed by the image.

    Here is the Qml code:
    Qt Code:
    1. Rectangle {
    2. id: detailImageRect
    3. width: parent.width
    4. height: parent.height - menuBar.height -30
    5. y: menuBar.height
    6. color: "#f6fda7"
    7. Flickable {
    8. id: flickable
    9. anchors.fill: parent
    10. contentHeight: imageToDisplay.height
    11. contentWidth: imageToDisplay.width
    12. clip: true
    13. Image {
    14. id: imageToDisplay
    15. source: fileNameLabel.text
    16. smooth: true
    17. asynchronous: true
    18. }
    19. MouseArea {
    20. id: dragArea
    21. hoverEnabled: true
    22. anchors.fill: parent
    23. onWheel: {
    24. imageToDisplay.scale += imageToDisplay.scale * wheel.angleDelta.y / 120 / 10;
    25. }
    26. }
    27. // Only show the scrollbars when the view is moving.
    28. states: State {
    29. name: "ShowBars"
    30. when: flickable.movingVertically || flickable.movingHorizontally
    31. PropertyChanges { target: verticalScrollBar; opacity: 1 }
    32. PropertyChanges { target: horizontalScrollBar; opacity: 1 }
    33. }
    34. transitions: Transition {
    35. NumberAnimation { properties: "opacity"; duration: 500 }
    36. }
    37. }
    38. }
    39. // Attach scrollbars to the right and bottom edges of the view.
    40. ScrollBar {
    41. id: verticalScrollBar
    42. width: 12; height: detailImageRect.height-12
    43. anchors.right: detailImageRect.right
    44. anchors.top: detailImageRect.top
    45. opacity: 0
    46. orientation: Qt.Vertical
    47. position: flickable.visibleArea.yPosition
    48. pageSize: flickable.visibleArea.heightRatio
    49. }
    50. ScrollBar {
    51. id: horizontalScrollBar
    52. width: detailImageRect.width-12; height: 12
    53. anchors.bottom: detailImageRect.bottom
    54. opacity: 0
    55. orientation: Qt.Horizontal
    56. position: flickable.visibleArea.xPosition
    57. pageSize: flickable.visibleArea.widthRatio
    58. }
    To copy to clipboard, switch view to plain text mode 

    I hope this helps.

    The lamb

Similar Threads

  1. Destructor overriding
    By Daylight in forum Qt Programming
    Replies: 13
    Last Post: 1st March 2013, 11:05
  2. Overriding Proxies
    By jdgrant in forum Qt Programming
    Replies: 0
    Last Post: 25th November 2011, 01:23
  3. Overriding global new
    By branko in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2010, 16:10
  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.