Hello,
I’m dynamically creating AppTextEdit
components in my app. I wan’t them to be created with the focus active – ie the cursor is showing on the newly created AppTextEdit
. However, the code below isn’t focussing the cursor as expected – I have to click on the text input before I can start typing something.
Thanks,
Phil
Main.qml:
import Felgo 3.0
import QtQuick 2.5
App {
id: app
EntityManager {
id: entityManager
entityContainer: page
}
Component {
id: textEditComponent
EntityBase {
entityType: "textEdit"
AppTextEdit {
id: textEdit
anchors.centerIn: parent
placeholderText: "type here"
width: dp(100)
}
}
}
Page {
id: page
anchors.fill: parent
AppButton {
anchors.top: parent.top
anchors.topMargin: dp(20)
anchors.horizontalCenter: parent.horizontalCenter
text: "create & focus"
onClicked: {
entityManager.removeAllEntities()
createEntity()
}
}
}
function createEntity() {
var props = {x: app.width/2, y: app.height/2}
var entityId = entityManager.createEntityFromComponentWithProperties(
textEditComponent,
props
);
var entity = entityManager.getEntityById(entityId)
entity.focus = true
console.log(entity.focus)
}
}