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

Few tooltip question



  • Hi everyone, I'm a new hand in qml, and my english is very poor.
    in my project, i have to implement a tooltip in some buttons.
    I saw some code here, and I found out this.
    http://qt-project.org/forums/viewthread/1686
    In this code, the tooltip will show up when the mouse move into the mouse area.
    How can I make the tooltip show up when mouse move into the mouse area and stay in mouse area for 3 or 5 seconds?
    Is there is a signal or function can detect how long the mouse stay in a mouse area?

    Thank for every response



  • Hi lesner,
    You can use Timer and listen hoverd event in MouseArea like this:
    @ Timer {
    id: timer

        repeat: false;
        running: false
        interval: 3000 // 3 sec.
        onTriggered: {
            console.log("show tip");
            button.hovered = true;
        }
    }
    
    
        MouseArea {
            id: ma
            anchors.fill: parent
            hoverEnabled: true
            onHoveredChanged: {
                console.log(ma.containsMouse);
                if (ma.containsMouse) {
                    timer.start();
                } else {
                    button.hovered = false;
                    timer.stop();
                }
            }
        }@


  • I don't think there is a signal for that. But I suppose you could solve this by starting a "Timer":http://doc.qt.nokia.com/4.7-snapshot/qml-timer.html when the mouse enters the area and interput it (using "stop()":http://doc.qt.nokia.com/4.7-snapshot/qml-timer.html#stop-method) if the mouse leaves before the Timer is finished. When the timer fires you just open the tooltip.



  • thanks a lot!!
    that's very useful !!


Log in to reply