Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-113669

KeyNavigation accepts key event when target doesn't change

    XMLWordPrintable

Details

    • All

    Description

      Problem

      KeyNavigation attached property, when used on a parent AND child item to redirect focus FROM parent TO child, whenever a child is focused it would accept subsequent key presses in that direction. This is bad because active focus does not change, but it doesn't let us react to the key press (e.g. animating that active focus hits the bounds).

      What actually happens is that a focused child item receives the arrow key press, but since it doesn't have any item for that direction, event bubbles up to the parent item, which does specify a KeyNavigation is that direction and its target is the same child item. So, parent handles the key press and forces focus onto an already focused item. Nothing visually changes, but we didn't get to handle the key press at the top-most level item (window's contentItem).

      Solution

      The first and most obvious solution is to alter the KeyNavigation algorithm to check whether the new to-be-focused Item is literally the same object as the current active focused one. And if so, stop processing and don't accept the event.

      Additional Information

      Note about attachment: Kirigami is not strictly needed, but helps visualizing active focus target. It is written with KF6 in mind (using newer JavaScript syntax than what's available in Qt 5), but can be easily ported back to KF5, or removed completely. Visualizing active focus is mostly useful in combination with another feature: play certain animations when key navigation hits the bounds.

      Attachments

        For Gerrit Dashboard: QTBUG-113669
        # Subject Branch Project Status CR V

        Activity

          People

            srutledg Shawn Rutledge
            ratijas ivan tkachenko
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change