[Development] QKeySequenceEdit questions
volker.hilsheimer at qt.io
Wed May 18 10:03:44 CEST 2022
> On 18 May 2022, at 09:45, Laszlo Papp <lpapp at kde.org> wrote:
> As a datapoint https://api.kde.org/frameworks/kguiaddons/html/classKeySequenceRecorder.html (which
> supports single letter shortcuts, used by KShortcutsDialog and co.).
> Thanks for sharing that.
> I do not know where the idea of "key sequence" comes from, but it does look like what we are looking for in practice is a "QShortcutEdit". Presumably, that is what KDE would also appreciate.
Have you ever used vim? :P Deleting until the end of the line, or deleting the next word, are all multi-chord key sequences.
> The current proposal is to make QKeySequenceEdit be able to behave like a QShortcutEdit by adding a property. But for keyboard shortcuts, "key sequence" does not make all that much sense. We are just retrofitting it for that purpose, I feel.
You are not forced to use key sequences with more than one chord, but in some applications, such as IDEs, multi-chord shortcuts are pretty common, even without using vim mode.
> For a truly clean solution and design, we would need to decouple the two, I feel.
> Anyway, hopefully, if QKeySequenceEdit becomes potent to behave like a QShortcutEdit widget, that is fine for now. Maybe, KDE could then drop its own solution in favor of what is available in Qt.
The status quo is: QKeySequenceEdit records a key, then gives you a second to press another key. If you don’t, then you have a one-chord key sequence. This repeats for up to four keyboards chords, which is probably more than anyone ever needs (or can remember).
Making QKeySequenceEdit consider the sequence complete after the nth key (rather than the hardcoded 4th) without waiting for that one second is probably all you need to do. No need for a whole new widget class.
QShortcut is then a programmatic construct that ties a QKeySequence into the event handling process and the signal/slot mechanism do that applications can respond to the key sequence being pressed. You never need the user to edit one of those. In very early Qt versions, QShortcut only stored a single key chord. QKeySequence was added later (Qt 3 maybe?) to be able to express multi-chord shortcuts, IIRC because we needed it in Qt Creator or even Qt Designer.
More information about the Development