遇到一个问题:写了个类似记事本的程序,但是程序运行时无法直接输入,需要点击后才能输入。
后面发现是焦点的问题,为了文本框有滚动条,添加了ScrollView ,但是没有给焦点。
ScrollView {
id: view
anchors.fill: parent
focus: true;//开启后,程序运行可直接输入
FocusScope {//覆盖的位置,点击后文本即可输入
id: scope
anchors.fill: parent
focus: true;
TextArea {
//无输入时的提示文本
placeholderText: "请输入文本噢,点击右上角即可置顶"
placeholderTextColor: "gray"
cursorVisible: true;
anchors.fill: parent;
wrapMode: TextEdit.Wrap//换行
font.pixelSize: 20;
focus: true;
textFormat:TextEdit.AutoText
selectByMouse:true;
selectByKeyboard: true
}
}
}