2

許容可能なテキストがある場合にボタンを有効にしたい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は常に無効になっています。どうすれば修正できますか?

4

1 に答える 1