tabChangesFocus property in TextArea is not working
-
wrote on 26 Jun 2015, 05:30 last edited by
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 } }
-
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 } }
Hi @advent,
It is a known bug. See QTBUG-39102. Still unresolved. -
Hi @advent,
It is a known bug. See QTBUG-39102. Still unresolved. -
@advent I think you can use "\t" for that purpose.
textArea.insert(2,"\t") //insert tab at position 2 //textArea = id of TextArea
-
@advent I think you can use "\t" for that purpose.
textArea.insert(2,"\t") //insert tab at position 2 //textArea = id of TextArea
wrote on 26 Jun 2015, 14:56 last edited by@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 insertingTab
character in TextArea can be done withCtrl+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 overrideTab
key?TextArea { id: textArea ... Keys.onPressed: { if (event.key == Qt.Key_Tab) { textArea.insert(/*current_position*/, "\t"); } } }
-
wrote on 26 Jun 2015, 15:15 last edited by
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; } } }
-
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; } } }
@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.
7/7