我有一個桌面QtQuick項目。這是非常簡單的:QML Keys.onEnterPressed問題
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
Rectangle {
width: 360
height: 360
Grid
{
id: xGrid
width: parent.width
height: parent.height
columns: 2
spacing: 1
Rectangle
{
height: parent.height
width: 10
color: "#ff0000"
Text {
id: xText
text: qsTr("t\na\ns")
}
}
TextEdit
{
id: xTextEdit
height: parent.height
width: 350
Keys.onEnterPressed: {
console.log(event.key)
xText.text = (qsTr("A"))
}
}
}
}
我的代碼不能運行像我想要的。該Keys.onEnterPressed
似乎從來沒有被捕獲,所以我儘量Keys.onPressed
它的工作,但不知道爲什麼,當我按下回車,該even.key
回報16777220.
任何一個得到這個問題?我該如何解決它?
感謝您的回答!
您的意思是,當您按下數字鍵盤上的「Enter」鍵(鍵碼16777221)時,它會被識別爲「返回」鍵(16777220)? – alexisdm 2012-03-13 03:18:38
是的,我認爲爲什麼我的代碼永遠不會觸發* Keys.onEnterPressed *! – nvcnvn 2012-03-13 03:44:49
你可以試試ReturnPressed處理程序嗎? – Kunal 2012-03-13 06:36:46