自定义 TextEdit,如何在 TextInput 变宽时隐藏它

use*_*815 3 text children input qml qtquick2

我正在尝试使用TextInput元素创建自定义文本字段(我需要它来使用验证器和自定义样式)。但我无法隐藏部分 TextInput 内容扩展(见图)。我对其他元素有类似的问题,虽然它有包含其他项目的根项目(容器),如果它们被放置在容器坐标之外,则可以看到子项。如果儿童部件不在根容器中,如何隐藏它们?

有代码,但它实际上只是模板,我尝试使用 uzez属性,但没有成功。

BreezeQuickLineInput.qml

import QtQuick 2.4

Item {
    id: root
    property int fontSize: 18
    property BreezeQuickPalette palette: BreezeQuickPalette
    property string text: "Type here..."
    implicitHeight: input.font.pixelSize*2
    implicitWidth: 196
    Rectangle{
        id: body
        color: "transparent"
        anchors.fill: parent
        border {
            color: palette.plasmaBlue
            width: 1
        }
        TextInput{
            id: input
            anchors {
                fill: parent
            }
            font.pointSize: fontSize
            color: palette.normalText
            selectByMouse: true
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

感谢任何帮助。我已经检查过TextInput文档,但是如果您知道我应该学习什么主题,请告诉我。

在此处输入图片说明

Vik*_*ngh 5

只需在文本输入中添加 clip:true 即可。这将解决您的问题。