Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Howto make the flickr example's search happen on the key presses?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    scarleton
    wrote on last edited by
    #1

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

    }
    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      Hi,

      You should be able to do this with something like:

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

      Regards,
      Michael

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved