我想在TextField
有可接受的文本时启用按钮(我正在使用validator
),并且此代码工作正常:
import QtQuick 2.3
import QtQuick.Controls 1.2
ApplicationWindow {
visible: true
width: 400
height: 100
id: mainWindow
property int _buttonSize: 30
property int _interval: 10
TextField {
y: _interval
width: parent.width
height: _buttonSize
id: ipInput
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
placeholderText: "IP"
validator: RegExpValidator
{
regExp:/^(([01]?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))\.){3}([01]?[0-9]?[0-9]|2([0-4][0-9]|5[0-5]))$/
}
}
Button {
enabled: ipInput.acceptableInput
id: go
anchors.horizontalCenter: parent.horizontalCenter
y: ipInput.y+_buttonSize+_interval
width: parent.width
height: _buttonSize
text: "GO"
}
}
所以,我添加Action
到这个Button
:
Button {
enabled: ipInput.acceptableInput
id: go
anchors.horizontalCenter: parent.horizontalCenter
y: ipInput.y+_buttonSize+_interval
width: parent.width
height: _buttonSize
text: "GO"
action: goAction
Action {
id: goAction
shortcut: "Enter"
enabled: go.enabled && go.visible
onTriggered: {
console.log("good")
}
}
}
现在Button
总是禁用。我该如何解决?