Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Mouse events



  • Hi guys,

    I found the example below on this site and I tried to modify it so I can play animations on mouse enter and exit events. The problem is when the mouse hovers over the different keys, the animations start/stop as expected. However, if I press the mouse left button key down then I drag the mouse around while holding the mouse button down, the animation stops when I leave the button area and does not start when I enter a different button area. My guess is that has to do with the original button still capturing the mouse and it is obvious because when I bring the mouse pointer back to the original button (where I originally pressed the mouse button down), the mouse down animation works fine. I'd like to figure out 1) if this is considered a mouse drag and move event? and 2) is there a way to fix this by forcing a mouse release in qml? 3) If the answer to my last question is no, then how can I do it on a Rectangle object in C++?

    Thanks in advance for your help.

    @Rectangle {
    id: content
    anchors.fill: parent
    radius: style.but_outer_radius
    smooth: true
    color: demoConstants.uiLightGrey

        KeyLabel
        {
            id: text_label_en
            text: button_pane.label_en
            state: "active"
            cstyle: button_pane.style
        }
        KeyLabel {
            id: text_label_other
            text: button_pane.label_other
            state: "inactive"
            cstyle: button_pane.style
        }
    
        Timer{
            id: autoRepeatTimer
            interval: autoRepeatInterval
            running: false
            repeat: true
    
            onTriggered: button_pane.sigButtonPressed( button_pane.currentKey())
        }
    
        MouseArea {
            hoverEnabled: true
    
            anchors.fill: parent
    
            onClicked:
            {
                button_pane.sigButtonPressed (button_pane.currentKey());
    
                mouse_btn_down_animation.stop();
                mouse_btn_up_animation.start();
            }
    
            onEntered:
            {
                mainWindow.sigOnMouseEnter(button_pane); )
    
                mouse_btn_up_animation.stop();
                mouse_btn_down_animation.start();
            }
    
            onExited:
            {
                mainWindow.sigOnMouseLeave(button_pane);
                mouse_btn_down_animation.stop();
                mouse_btn_up_animation.start();
                
                button_pane.border.color = style.col_but_border
                autoRepeatTimer.running = false;
            }
    
            onReleased:
            {
                mouse_btn_down_animation.stop();
                mouse_btn_up_animation.start();
                autoRepeatTimer.running = false;
            }
    
            onPressed:
            {
                mouse_btn_up_animation.stop();
                mouse_btn_down_animation.start();
            }
    
            onPressAndHold:
            {
                autoRepeatTimer.running = button_pane.autoRepeat;
            }
        }@


  • Bumping this topic to top hoping that someone will be able to help answer my questions.


Log in to reply