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

QKeySequence doesn't encode and decode modifier only shortcuts as expected

    XMLWordPrintable

Details

    • Linux/Wayland, Linux/X11

    Description

      Modifier only shortcuts are shortcuts that are made of only modifier keys, for example Alt+Shift, etc. They have various use cases, e.g. push-to-talk, layout switching, etc.

      Examples of modifier only shortcuts:

      • Windows: Win to open the start menu, or Ctrl+Shift to switch between keyboard layouts
      • Linux: in Plasma, every shortcut can contain either modifier keys or modifiers keys plus a normal key; user can also create their own shortcuts or reassign the keys of the existing shortcuts; in GNOME, Meta can be used to open the overview
      • macOS: modifier only shortcuts aren't common on mac
      • PTT: the Alt key is often used for push-to-talk (although it depends greatly on user preferences)

      Normal shortcuts, e.g. Ctrl+A, are expected to be triggered on key press. Modifier only shortcuts are triggered depending on the context. For example, with push-to-talk, they are triggered on key press, but an application launcher may be triggered on key release (to avoid accidentally triggering when pressing a shortcut that starts with the same modifiers). The keys in a modifier only shortcut can be pressed in any order, e.g. Meta+Shift or Shift+Meta.

      There are two issues with encoding and decoding modifier only shortcuts:

      • QKeySequence::toString() will append a plus after the modifier keys, e.g. "Meta+Ctrl+"
      • QKeySequence::fromString() fails to parse modifier only shortcuts

      One potential workaround is to convert the last modifier key from Qt::KeyboardModifier to Qt::Key when constructing a QKeySequence object and then converting it back to Qt::KeyboardModifier when saving the QKeySequence to the disk, but it results in increased code complexity.

      The expected behavior is:

      • QKeySequence(Qt::MetaModifier + Qt::ControlModifier).toString() returns "Meta+Ctrl"
      • QKeySequence::fromString("Meta+Ctrl") returns a QKeySequence object with Qt::MetaModifier and Qt::ControlModifier
      • note that QKeySequence::fromString("Meta+Ctrl+") should still fail to parse

      Attachments

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

        Activity

          People

            srutledg Shawn Rutledge
            zzag Vlad Zahorodnii
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: