c++ - QML 矩形按钮高亮延迟

标签 c++ qt qml delay highlight

我有一个按钮列表,当用户按下它直到它被释放时,我想单独突出显示这些按钮。

问题在于,当您滚动列表时,您触摸的第一个按钮将突出显示,即使您触摸它一毫秒也是如此。它看起来不太好,所以我想为高亮动画添加延迟。

我认为在高亮动画发生之前稍作延迟可能会解决这个外观问题。

如何为高亮动画添加延迟?

我一直在尝试类似的东西:

Rectangle {
    id: folderButton    
    property bool pressed: false
    signal clicked

    height: mainWindoww.height * 0.1
    width: parent.width
    color: pressed ? "lightgrey" : "white"

    function release() {
        autoRepeatClicks.stop()
        folderButton.pressed = false
    }

    SequentialAnimation on pressed {
        id: autoRepeatClicks
        running: false

        PropertyAction { target: folderButton; property: "pressed"; value: true }
        ScriptAction { script: folderButton.clicked() }
        PauseAnimation { duration: 1000 }

        SequentialAnimation {
            loops: Animation.Infinite
            ScriptAction { script: folderButton.clicked() }
            PauseAnimation { duration: 500 }
        }
    }

    MouseArea {
        anchors.fill: parent

        onPressed: autoRepeatClicks.start()
        onReleased: folderButton.release()
        onCanceled: folderButton.release()
    }
}

但是这段代码好像没有加任何时差

最佳答案

您可以使用 Timer为了达成这个。例如,您可以这样做:

Item {
    Timer {
        interval: 500;
        running: true;
        repeat: true
        onTriggered: time.text = Date().toString()
    }

    Text { id: time }
}

关于c++ - QML 矩形按钮高亮延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29681606/

相关文章:

c++ - 如何从缩放图像中知道真实图像中的坐标

qt - 在 Qt Creator 中关闭闪烁的光标

c++ - 如何迭代字符串 vector 的 vector ? (c++)

c++ - 多次调用 make_shared() 时的 shared_ptr 垃圾回收

c++ - QT中子UI窗口打开时如何关闭父UI窗口

ios - QtPositioning 5.3,QML PositionSource 在 ios 8.1 上不返回任何数据?

qt - 如何使用 QML 更改 Qt3D 中对象的纹理或颜色?

Qt QML : in-file definition of reusable objects

c++ - 无法从辅助函数调用模板函数

c++ - 当 chrome 是默认浏览器时,ShellExecute 无法在 Windows 8 上打开页面