Qt World Summit: Submit your Presentation

Using MouseWheel for zoom: too many wheel events

  • 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?

  • 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
                id: zoomPosDelay
                running: false
                repeat: false
                interval: 500
            onWheel: {
                if(zoomPosDelay.running==false) {
                    zoomX = plot.xPixToData(mouseX)
                    zoomY = plot.yPixToData(mouseY)
                if(wheel.angleDelta.y>0) {

    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?

Log in to reply