Qt Quick输入项目中不存在该属性。您可以投票支持here功能。
在此期间,您可以使用Qt Quick Controls 2中的TextArea
。
如果您更愿意使用纯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
}
}
}
这有点旧,但我发现Android构建的另一个必要条件。由于Android只在虚拟键盘中按ok后发送文本编辑信号,因此占位符仍然存在。所以为了避免它,我建议:
TextEdit {
id: textEdit
width: 200
height: 50
property string placeholderText: "Enter text here..."
Text {
text: textEdit.placeholderText
color: "#aaa"
visible: !textEdit.text && !textEdit.activeFocus // <----------- ;-)
}
}