onEditingFinished из QML TextInput не запускается - PullRequest
0 голосов
/ 03 июня 2019

У меня есть следующий ButtonInputIcon предмет, который включает TextInput. Однако я не смог поймать сигнал editingFinished из TextInput. Что я делаю не так?

Rectangle {
    width: 86
    height: 48
    property bool buttonActive: true
    property url iconSource: "../images/IC066UpDown.svg"
    property real iconSize: 0.60
    property alias textInputText: textInput.text

    color: buttonActive ? Style.buttonColorOn : Style.buttonColorOff
    radius: 5
    property alias inputMouse: inputMouse
    property alias textInput: textInput

    Rectangle {
        id: borderRect
        anchors.left: parent.left
        anchors.leftMargin: 8
        anchors.right: icon.left
        anchors.rightMargin: 8
        anchors.top: parent.top
        anchors.topMargin: 6
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 6
        border.color: buttonActive ? Style.buttonColorTextOn : Style.buttonColorTextOff
        color: parent.color
        border.width: 1

        TextInput {
            id: textInput
            color: buttonActive ? Style.buttonColorTextOn : Style.buttonColorTextOff
            text: "10"
            anchors.verticalCenter: parent.verticalCenter
            anchors.right: parent.right
            anchors.rightMargin: 5
            inputMask: "999"
            maximumLength: 3
            selectionColor: "green"
            font.family: stdFont.name
            font.pixelSize: 20
        }

        MouseArea {
            id: inputMouse
            anchors.fill: borderRect
        }
    }

    Image {
        id: icon
        sourceSize.height: parent.height * iconSize
        anchors.verticalCenter: parent.verticalCenter
        anchors.right: parent.right
        anchors.rightMargin: 10
        fillMode: Image.PreserveAspectCrop
        source: iconSource
        antialiasing: false
        visible: false
    }

    ColorOverlay {
        color: buttonActive ? Style.buttonColorTextOn : Style.buttonColorTextOff
        anchors.fill: icon
        source: icon
    }
}

Я пытаюсь поймать сигнал editFinished здесь, в его файле .qml.

ButtonInputIconForm {

    textInput.onFocusChanged: console.info("textinput")
    textInput.onEditingFinished:
    {
        console.info("Editing finished ", textInputText)
    }

    inputMouse.onClicked: {
        textInput.focus = true
    }
}

EDIT: Я еще больше упростил код и теперь запускаю его в самом простом из возможных приложений. Я до сих пор не вижу сигнал, срабатывающий, когда onEditingFinished должен сработать. Ниже приводится новый код.

Код в ButtonInputIconForm.ui.qml:

import QtQuick 2.4
import QtGraphicalEffects 1.12

Rectangle {
    width: 86
    height: 48
    property bool buttonActive: true
    property real iconSize: 0.60
    property alias textInputText: textInput.text

    color: "green"
    property alias inputMouse: inputMouse
    property alias textInput: textInput

    Rectangle {
        id: borderRect
        anchors.left: parent.left
        anchors.leftMargin: 8
        anchors.right: icon.left
        anchors.rightMargin: 8
        anchors.top: parent.top
        anchors.topMargin: 6
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 6
        border.color: "red"
        color: parent.color
        border.width: 1

        TextInput {
            id: textInput
            color: "black"
            text: "10"
            anchors.verticalCenter: parent.verticalCenter
            anchors.right: parent.right
            anchors.rightMargin: 5
            inputMask: "999"
            maximumLength: 3
            selectionColor: "blue"
            font.pixelSize: 20
        }

        MouseArea {
            id: inputMouse
            anchors.fill: borderRect
        }
    }

    Image {
        id: icon
        sourceSize.height: parent.height * iconSize
        anchors.verticalCenter: parent.verticalCenter
        anchors.right: parent.right
        anchors.rightMargin: 10
        antialiasing: false
        visible: false
    }
}

Код в ButtonInputIcon.qml:

import QtQuick 2.4

ButtonInputIconForm
{
    textInput.onActiveFocusChanged:
    {
        if (activeFocus)
        {
            console.info("active focus on textinput")
        }
        else
        {
            console.info("active focus not on textinput")
        }
    }

    textInput.onFocusChanged: console.info("focus on textinput")

    inputMouse.onClicked: {
        textInput.focus = true
    }
}

код в main.qml

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    property alias buttonIcon: buttonIcon
    ButtonInputIcon{
        id: buttonIcon
        textInput.onEditingFinished:
        {
            console.info("buttonIcon.textInput.onEditingFinished", buttonIcon.textInputText)
        }
    }
}

РЕДАКТИРОВАТЬ 2

Я узнал, что из-за того, что я установил inputMask: "999", onEditingFinished запускается только тогда, когда перед нажатием кнопки ввода вводится 3-значное число. Вот в чем проблема.

...