У меня проблема с моим QML. Я хотел бы отредактировать TextInput
на основе действия, установив для атрибута focus
значение true
. Он работает, когда TextInput
находится в Rectangle
, но не в ScrollView
. Вот пример:Редактирование текстового ввода в ScrollView
Item {
id: main
width: 640
height: 480
ScrollView{
id: scrollView
height: parent.height/2
width: parent.width
Rectangle{
border.color: "black"
border.width: 1
anchors.centerIn: parent
height: 25
width: 200
TextInput{
id: ti1
anchors.fill: parent
verticalAlignment: TextInput.AlignVCenter
horizontalAlignment: TextInput.AlignHCenter
}
}
}
Rectangle{
y: height
height: parent.height/2
width: parent.width
Rectangle{
border.color: "black"
border.width: 1
anchors.centerIn: parent
height: 25
width: 200
TextInput{
id: ti2
anchors.fill: parent
verticalAlignment: TextInput.AlignVCenter
horizontalAlignment: TextInput.AlignHCenter
}
}
}
MouseArea{
anchors.fill: parent
onClicked: {
if (mouseY < parent.height/2){
ti2.focus = false
ti1.focus = true
}else{
ti1.focus = false
ti2.focus = true
}
}
}
}
Когда я нажимаю на нижней части окна, то TextInput
ti2 редактируется. Но когда я нажимаю на верхнюю половину, ti1 нет.
Есть ли у кого-нибудь идеи? Поведение такое же, как и у TextEdit
.
Спасибо.