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. Cannot retreive focus in TextEdit inside a StackView item.
Qt 6.11 is out! See what's new in the release blog

Cannot retreive focus in TextEdit inside a StackView item.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 1.0k Views 2 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.
  • MikhailGM Offline
    MikhailGM Offline
    MikhailG
    wrote on last edited by MikhailG
    #1

    Hello! I do not understand why it does not work properly. I want to set TextEdit focus to true when the window pops out. TextEdit can receive key events only after a click has been performed on its area.

    main.qml

    ApplicationWindow {
        id:aplWin
        visible: true
        minimumWidth:  1280
        minimumHeight: 1024
    
        StackView {
            id: stackView
            anchors.fill: parent
            initialItem: SignInWin {}
        }
    }
    

    SignInWin.qml

    Page {
        id: root
        width: parent.width + 500
        height: parent.height
    
        Rectangle {
            border.color: "black"
            y: 200
            width: 50
            height: 20
            z: 1
            TextEdit {
                anchors.fill: parent
                color: "black"
                focus: true
            }
        }
    }
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      stcorp
      wrote on last edited by
      #2

      Getting focus to work correctly has always been difficult for me, but I think in this case you also need to set the focus of your StackView to true as well. I just tested it, you also need to set the focus of the Page is SignInWin to true. Then it will work as you want it to.

      The problem is I don't really know why it works this way. I would need to read more documentation or ask someone who really understand how focus works to really understand this.

      MikhailGM 1 Reply Last reply
      1
      • S stcorp

        Getting focus to work correctly has always been difficult for me, but I think in this case you also need to set the focus of your StackView to true as well. I just tested it, you also need to set the focus of the Page is SignInWin to true. Then it will work as you want it to.

        The problem is I don't really know why it works this way. I would need to read more documentation or ask someone who really understand how focus works to really understand this.

        MikhailGM Offline
        MikhailGM Offline
        MikhailG
        wrote on last edited by
        #3

        @stcorp my man awesome! thank you

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mohsen Zahraee
          wrote on last edited by
          #4

          you can try this example in SignInWin.qml :

          Page {
              id: root
              width: parent.width + 500
              height: parent.height
              focus: true
          
              Rectangle {
                  border.color: "black"
                  y: 200
                  width: 50
                  height: 20
                  z: 1
                  TextEdit {
                      id:txt
                      anchors.fill: parent
                      color: "black"
                      focus: true
                  }
              }
              Component.onCompleted:{
          
                  txt.forceActiveFocus()
              }
          }
          
          1 Reply Last reply
          1

          • Login

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