Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt5.1 TextField - Keys attached property - capturing key-presses
Qt 6.12 LTS is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.7k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      g1ennr
      wrote on last edited by
      #2

      Hi Viv,

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

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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

        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
        • Unsolved