Howto make the flickr example's search happen on the key presses?



  • I am working on a search where I would like the search to happen as text is entered. This is the same functionality as the demo program flickr. The demo program has the TextInput in the title bar to allow the user to enter text. When the user clicks the Ok button or pressed Enter/Return key, it calls the accept() function which performs the search.

    I have taken the code from the flickr example and put it into my app, then tried to get accept() to be called upon each key press, but it only fires under the conditions above. Any thoughts? Here is the flickr code:
    @Item {
    id: lineEdit
    y: 4; height: parent.height - 9
    anchors { left: tagButton.right; leftMargin: 5; right: parent.right; rightMargin: 5 }

    BorderImage { source: "images/lineedit.sci"; anchors.fill: parent }
    
    TextInput {
        id: editor
        anchors {
            left: parent.left; right: parent.right; leftMargin: 10; rightMargin: 10
            verticalCenter: parent.verticalCenter
        }
        cursorVisible: true; font.bold: true
        color: "#151515"; selectionColor: "Green"
    }
    
    Keys.forwardTo: [ (returnKey), (editor)]
    
    Item {
        id: returnKey
        Keys.onReturnPressed: container.accept()
        Keys.onEnterPressed: container.accept()
        Keys.onEscapePressed: titleBar.state = ""
    }
    

    }
    @

    And here is my code:

    @Rectangle
    {
    id: editorRectangle
    height: 40
    radius: 3
    anchors { left: parent.left; leftMargin: 185; top: parent.top; topMargin: 10; right: parent.right; rightMargin: 10 }

    TextInput {
        id: editor
        width: 255
        height: 31
        //text: stationManager.favoriteModel
        selectByMouse: true;
        anchors.margins: 4
        anchors.fill: parent
        smooth: true
        clip: true
        cursorVisible: true
        font.pixelSize: 24
    }
    
    Keys.forwardTo: [ (excapeKey), (editor)]
    
    Item {
        id: excapeKey;
        Keys.onReturnPressed: container.accept();
        Keys.onEnterPressed: container.accept();
        Keys.onEscapePressed: { editor.text = ""; container.accept(); }
    }
    

    }
    @



  • Hi,

    You should be able to do this with something like:

    @
    TextInput {
    ...
    onTextChanged: container.accept()
    }
    @

    Regards,
    Michael


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.