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. tabChangesFocus property in TextArea is not working

tabChangesFocus property in TextArea is not working

Scheduled Pinned Locked Moved QML and Qt Quick
qtquicktextareatab key
7 Posts 2 Posters 3.4k Views
  • 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.
  • A Offline
    A Offline
    advent
    wrote on 26 Jun 2015, 05:30 last edited by
    #1

    As explained in documentation here: http://doc.qt.io/qt-5/qml-qtquick-controls-textarea.html#tabChangesFocus-prop

    I expect the Tab key in TextArea to be accepted as input not to change the focus. But in my QML code below, whatever tabChangesFocus value assigned, it keep changing the focus into next element. I use Qt 5.4 and qmlscene to preview the QML file.

    import QtQuick 2.4
    import QtQuick.Controls 1.3
    import QtQuick.Layouts 1.1
    
    ColumnLayout {
        id: columnLayout1
    
        RowLayout {
            id: rowLayout1
            anchors.top: parent.top
            anchors.topMargin: 0
            anchors.left: parent.left
            anchors.right: parent.right
    
            TextField {
                id: textField1
                placeholderText: qsTr("Text Field")
                Layout.fillWidth: true
            }
    
            Button {
                id: btnAdd
                text: qsTr("Add")
            }
    
            Button {
                id: btnClose
                text: qsTr("Close")
            }
        }
    
        TextArea {
            id: textArea1
            Layout.fillHeight: true
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 0
            anchors.right: parent.right
            anchors.rightMargin: 0
            anchors.left: parent.left
            anchors.leftMargin: 0
            tabChangesFocus: false
        }
    }
    
    P 1 Reply Last reply 26 Jun 2015, 06:49
    0
    • A advent
      26 Jun 2015, 05:30

      As explained in documentation here: http://doc.qt.io/qt-5/qml-qtquick-controls-textarea.html#tabChangesFocus-prop

      I expect the Tab key in TextArea to be accepted as input not to change the focus. But in my QML code below, whatever tabChangesFocus value assigned, it keep changing the focus into next element. I use Qt 5.4 and qmlscene to preview the QML file.

      import QtQuick 2.4
      import QtQuick.Controls 1.3
      import QtQuick.Layouts 1.1
      
      ColumnLayout {
          id: columnLayout1
      
          RowLayout {
              id: rowLayout1
              anchors.top: parent.top
              anchors.topMargin: 0
              anchors.left: parent.left
              anchors.right: parent.right
      
              TextField {
                  id: textField1
                  placeholderText: qsTr("Text Field")
                  Layout.fillWidth: true
              }
      
              Button {
                  id: btnAdd
                  text: qsTr("Add")
              }
      
              Button {
                  id: btnClose
                  text: qsTr("Close")
              }
          }
      
          TextArea {
              id: textArea1
              Layout.fillHeight: true
              anchors.bottom: parent.bottom
              anchors.bottomMargin: 0
              anchors.right: parent.right
              anchors.rightMargin: 0
              anchors.left: parent.left
              anchors.leftMargin: 0
              tabChangesFocus: false
          }
      }
      
      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 26 Jun 2015, 06:49 last edited by
      #2

      Hi @advent,
      It is a known bug. See QTBUG-39102. Still unresolved.

      157

      A 1 Reply Last reply 26 Jun 2015, 10:14
      1
      • P p3c0
        26 Jun 2015, 06:49

        Hi @advent,
        It is a known bug. See QTBUG-39102. Still unresolved.

        A Offline
        A Offline
        advent
        wrote on 26 Jun 2015, 10:14 last edited by
        #3

        @p3c0 Hi, thanks for the information! Btw, is there any way to force Tab as input?

        P 1 Reply Last reply 26 Jun 2015, 10:41
        0
        • A advent
          26 Jun 2015, 10:14

          @p3c0 Hi, thanks for the information! Btw, is there any way to force Tab as input?

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 26 Jun 2015, 10:41 last edited by
          #4

          @advent I think you can use "\t" for that purpose.

          textArea.insert(2,"\t") 
          //insert tab at position 2
          //textArea = id of TextArea
          

          157

          A 1 Reply Last reply 26 Jun 2015, 14:56
          0
          • P p3c0
            26 Jun 2015, 10:41

            @advent I think you can use "\t" for that purpose.

            textArea.insert(2,"\t") 
            //insert tab at position 2
            //textArea = id of TextArea
            
            A Offline
            A Offline
            advent
            wrote on 26 Jun 2015, 14:56 last edited by
            #5

            @p3c0 Sorry, that's not what I really mean. I want to force the TextArea (if it's possible) to accept Tab key as character. I know inserting Tab character in TextArea can be done with Ctrl+Tab, but I don't like that. The bug has been there for like a year. Is there any workaround?

            Btw, I tried to override the Tab key behavior in QML, but it's just doesn't work. Is this correct way to override Tab key?

            TextArea {
                id: textArea
                ...
                Keys.onPressed: {
                    if (event.key == Qt.Key_Tab) {
                        textArea.insert(/*current_position*/, "\t");
                    }
                }
            }
            
            1 Reply Last reply
            0
            • A Offline
              A Offline
              advent
              wrote on 26 Jun 2015, 15:15 last edited by
              #6

              Finally, I can figure it out. Here is the code to override the Tab key change focus behavior:

              TextArea {
                  id: textArea
                  ...
                  Keys.onPressed: {
                      if (event.key == Qt.Key_Tab) {
                          insert(cursorPosition, "\t");
                          event.accepted = true;
                      }
                  }
              }
              
              P 1 Reply Last reply 27 Jun 2015, 05:27
              2
              • A advent
                26 Jun 2015, 15:15

                Finally, I can figure it out. Here is the code to override the Tab key change focus behavior:

                TextArea {
                    id: textArea
                    ...
                    Keys.onPressed: {
                        if (event.key == Qt.Key_Tab) {
                            insert(cursorPosition, "\t");
                            event.accepted = true;
                        }
                    }
                }
                
                P Offline
                P Offline
                p3c0
                Moderators
                wrote on 27 Jun 2015, 05:27 last edited by
                #7

                @advent Glad that you found the solution. Thanks for sharing. Please mark the post as solved so that it would be helpful to others too.

                157

                1 Reply Last reply
                0

                4/7

                26 Jun 2015, 10:41

                • Login

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