Forums

OverviewFelgo 2 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.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support