可以使用onTextChanged信号来实时监控TextArea输入的文本内容,并在信号回调中更新提示限定输入的字数。具体实现如下:

在TextArea中添加onTextChanged信号回调函数:

TextArea {
    // ...

    onTextChanged: {
        idTipsInputAstrict.text = (text.length + '/240')
    }
}

在Label中显示当前输入的字数:

Label {
    id: idTipsInputAstrict
    // ...

    text: qsTr('0/240')  // 初始值为0

    // ...
}

原文地址: https://www.cveoy.top/t/topic/nVHZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录