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. TextInput with persistent focus
Forum Updated to NodeBB v4.3 + New Features

TextInput with persistent focus

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 603 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.
  • P Offline
    P Offline
    poor_robert
    wrote on last edited by
    #1

    Hello,

    I have following qml file:

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Controls.Styles 1.4
    
    Rectangle {
    	id: applicationWindow1
    	visible: true
    	width: 640
    	height: 480
    
    	TextField
    	{
    
    		 id: textInput1
    		 width: 193
    		 height: 130
    		 anchors.horizontalCenter: parent.horizontalCenter
    		 anchors.verticalCenter: parent.verticalCenter
    		 anchors.left: parent.left
    		 anchors.leftMargin: 193
    		 anchors.top: parent.top
    		 anchors.topMargin: 130
    		 focus: true
    
    		 text: qsTr("Text Input")
    
    		 font.pixelSize: 12
    
    	 }
    
    	 Button
    	 {
    		id: button1
    		y: 403
    		text: qsTr("Backspace")
    		anchors.bottom: parent.bottom
    		anchors.bottomMargin: 37
    		anchors.left: parent.left
    		anchors.leftMargin: 257
    
    		onClicked:
    		{
    			console.log(textInput1.text.length)
    			textInput1.remove(textInput1.text.length-1, textInput1.text.length)
    		}
    	 }
    
    	Component.onCompleted:
    	{
    		textInput1.forceActiveFocus(Qt.OtherFocusReason)
    	}
    }
    

    I would like to keep keyboard focus inside the TextInput even if the "Backspace" button was pressed. Do you have any idea/hints how to achieve this?

    1 Reply Last reply
    0
    • jpnurmiJ Offline
      jpnurmiJ Offline
      jpnurmi
      wrote on last edited by jpnurmi
      #2

      You can set the desired focusPolicy. For example:

      Button { focusPolicy: Qt.NoFocus } // no focus at all
      Button { focusPolicy: Qt.TabFocus } // allow tab focus, but not click focus
      
      1 Reply Last reply
      0
      • P Offline
        P Offline
        poor_robert
        wrote on last edited by
        #3

        Hello jpnurmi :-),

        Thank you for the reply,

        I think, that this is something what I was looking for.
        Thank you :)

        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