Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Using MouseWheel for zoom: too many wheel events

Using MouseWheel for zoom: too many wheel events

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 914 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxwell31
    wrote on last edited by maxwell31
    #1

    Hi,

    I have my custom plot, into which I want to zoom using the mouse wheel. My problem is, that when I scroll the wheel fast, I do not get one wheel event with a big angleDelta.y but several wheel events with the same angleDelta.y. This is problematic for me, because the mouseX position sets the center of the zoom. Thus if the wheel is scrolled fast, also the center is moving. Do you have a suggestion how I could improve this?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maxwell31
      wrote on last edited by
      #2

      Ok, I have a solution using a timer:

      MouseArea {
              id: zoomArea
              anchors.fill: parent
              acceptedButtons: Qt.LeftButton
              hoverEnabled: true
      
              property double zoomX: 0 // used as zoom position for wheel scrolling
              property double zoomY: 0 // used as zoom position for wheel scrolling
              Timer{
                  id: zoomPosDelay
                  running: false
                  repeat: false
                  interval: 500
              }
              onWheel: {
                  if(zoomPosDelay.running==false) {
                      zoomX = plot.xPixToData(mouseX)
                      zoomY = plot.yPixToData(mouseY)
                  }
                  zoomPosDelay.start()
      
                  if(wheel.angleDelta.y>0) {
                      plot.setViewZoomWheel(zoomX,zoomY,1.2)
      

      But my zoom does not feel natural yet. The problem is, that center the plot around the mouse position before the wheel event, which results in a big jump (translation) of the area. What is the standard way to deal with this e.g. in maps?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved