【问题标题】:QML Keys.onReleased fire when pressing keyQML Keys.onReleased 按键时触发
【发布时间】:2019-06-20 09:46:06
【问题描述】:

环境:

Qt 5.13 + Mingw32 + Windows 10 64bit

Qt 5.11 + Mingw32 + Windows 10 64bit

演示代码:

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    Item {
        id: name
        anchors.fill: parent
        focus: true
        Keys.onReleased: console.log("onReleased")
    }
}

问题:QML Keys.onReleased 按键时触发(任意键)

【问题讨论】:

    标签: windows qt qml mingw32


    【解决方案1】:

    通过运行您的示例,我假设您的问题发生在持有密钥后。

    为防止您在捕获KeyEvent 时简单地检查isAutoRepeat 属性:

    Keys.onReleased: if (!event.isAutoRepeat) console.log("onReleased")
    

    【讨论】:

      【解决方案2】:

      你可以从event查看isAutoRepeat

      Item {
          id: name
          anchors.fill: parent
          focus: true
          Keys.onReleased: {
              if (!event.isAutoRepeat)
                  console.log("released")
              else
                  console.log("repeated like in a text field")
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-03-15
        • 1970-01-01
        • 2019-07-29
        • 2013-01-23
        • 1970-01-01
        • 1970-01-01
        • 2016-10-25
        相关资源
        最近更新 更多