Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › Entity creation and focus

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #21276

    Phil

    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)
        }
    }

     

    #21277

    Phil

    I found the answer to my own question. I’m missing an alias to AppTextEdit

    import Felgo 3.0
    import QtQuick 2.5
    
    App {
        id: app
    
        EntityManager {
            // ...
        }
    
        Component {
            id: textEditComponent
            EntityBase {
                entityType: "textEdit"
                property alias textEditAlias: textEdit
                AppTextEdit {
                    id: textEdit
                    // ...
                }
            }
        }
    
        Page {
            // ...
        }
    
        function createEntity() {
            // ...
            entity.textEditAlias.focus = true
            // ...
        }
    }

     

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded