Mit*_*tch 14
Qt Quick输入项目中不存在该属性.您可以在此投票支持该功能.
在此期间,您可以使用TextAreaQt Quick Controls 2.
如果您更愿意使用纯Qt Quick,您可以执行与控件相似的操作,并Text在字段上方添加项目:
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
width: 300
height: 300
visible: true
TextEdit {
id: textEdit
width: 200
height: 50
property string placeholderText: "Enter text here..."
Text {
text: textEdit.placeholderText
color: "#aaa"
visible: !textEdit.text
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
这有点旧,但我发现Android 构建的另一个必需品。由于 Android 仅在您在虚拟键盘中按“确定”后才发送文本编辑信号,因此占位符仍保留在那里。因此,为了避免这种情况,我建议:
TextEdit {
id: textEdit
width: 200
height: 50
property string placeholderText: "Enter text here..."
Text {
text: textEdit.placeholderText
color: "#aaa"
visible: !textEdit.text && !textEdit.activeFocus // <----------- ;-)
}
}
Run Code Online (Sandbox Code Playgroud)