При использовании Keys
в качестве присоединенного свойства qml
, но Keys.onReleased
было выполнено, когда не было ключевого события released
!как это решить?
import QtQuick 2.4
Item {
property string imagePath
property string btnText
property string btnColor: "white"
property double btnWidth: 0
property double btnHeight: 0
property double btnRadius: 0
property double btnTextSize: 0
property double btnOpcity: 0.9
property bool btnEnable: true
property int spaceKeyEventTimes:0
id: umButton
width: 100
height: 100
Rectangle{
id: umButton_Rec
width: btnWidth
height: btnHeight
color: btnColor
radius: btnRadius
opacity: btnOpcity
focus: true
Text{
//focus: true
style: Text.Raised
text: btnText
font.pixelSize: 29
}
}
//////////////Handle KeyEvent from the system//////////////////
Keys.enabled: true;
Keys.onPressed: {
switch(event.key)
{
case Qt.Key_Space:
console.log( "emit btnPressed()" )
event.accepted = true
break;
default:
break;
}
}
Keys.onReleased: {
switch(event.key)
{
case Qt.Key_Space://Qt.Key_Space
console.log("emit btnReleased()")
event.accepted = true
break;
default:
break;
}
}
}