Qt5.1 TextField - Keys attached property - capturing key-presses



  • Hey,

    With the following code:

    @import QtQuick 2.1
    import QtQuick.Controls 1.0
    import QtQuick.Layouts 1.0

    ApplicationWindow {
    title: qsTr("Some App")
    ColumnLayout {
    Rectangle {
    color: "Blue"
    width: 50
    height: 50
    focus: true
    Keys.priority: Keys.BeforeItem
    Keys.onPressed: res.text = res.text == "" ? "Rect" : "";
    }
    TextField {
    text: "Some Text"
    KeyNavigation.priority: KeyNavigation.BeforeItem
    Keys.priority: Keys.BeforeItem
    Keys.onPressed: res.text = res.text == "" ? "TextField" : "";
    Keys.onReturnPressed: res.text = res.text == "" ? "TextField" : "";
    Keys.onSpacePressed: res.text = res.text == "" ? "TextField" : "";
    }
    TextField {
    id: res
    }
    }
    }@

    It seems the attached property for TextField even with "Keys.priority: Keys.BeforeItem":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-keys.html#priority-prop does not seem to trigger the events for onPressed whereas a Rectangle or Item do so just fine.

    Also OnReturnPressed / onReleased works just fine on TextField. (in onReleased however, setting event.accepted seems to have no effect as the text still appears in the TextField indicating either the Keys.onReleased got called after the TextField handlers or the event.accepted = true; was ignored)

    This kinda suggests, the events are getting handled internally and thus getting accepted thereby not triggering the onPressed for any standard keys which get handled by the TextField. "Enter" is rightfully so not handled and thereby propagates up to our capture event.

    The documentation for "Keys.priority":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-keys.html#priority-prop states that

    bq. This property determines whether the keys are processed before or after the attached item's own key handling.

    so why is specifying "Keys.BeforeItem" not acting as expected? Is there anything additional that's needed to capture all key-events in a TextField?

    Threads like "This":http://developer.nokia.com/Community/Discussion/showthread.php/232027-quot-Enter-quot-key-on-the-TextArea-in-QML state what I'm trying should work fine on a TextField. However seeing it's from 2011 not sure if it even applies or if I'm just missing something.



  • Hi Viv,

    I have noticed the same thing. Did you find out how to intercept keypresses from TextField?



  • Hey @g1ennr

    Nope, Currently this does not seem to be possible with TextField. I have a bug submitted for this. Seems @Jens is currently assigned to it and he seems to prefer TextField having this functionality as well. Not sure if there is any progress on the issue. You can find the issue "Here":https://bugreports.qt-project.org/browse/QTBUG-34101


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.