[Development] Application wide shortcuts API for QML

Mark markg85 at gmail.com
Tue Dec 11 20:46:36 CET 2012


On Tue, Dec 11, 2012 at 8:04 PM, Rick Stockton
<rickstockton at reno-computerhelp.com> wrote:
> On 12/11/2012 12:53 AM, Mark wrote:
>> Hi,
>>
>> Alan' posts about possible future APIs made me want to post this as
>> well. In the QWidget works we have the rather nice QShortcut class to
>> aid us in defining application wide shortcuts.
>>
>> Functionality like that is completely missing from the current QtQuick
>> in both Qt 4.8 (1.1) and 5.0 (2.0). For desktop based applications an
>> API like that would be very much needed since applications need to
>> have the ability to define app wide shortcuts.
>>
>> I already made an API for exactly this reason which can be found here [1].
>>
>> The API itself should look somewhat like this:
>>
>> Shortcut {
>>     QKeySequence key
>>     signal activated
>> }
>>
>> Obviously if this is going to happen then mouse shortcuts should be
>> included as well. Right now Qt itself has no possibility of defining a
>> shortcut like "CTRL + LEFT MOUSE BUTTON" (or i don't know of it's
>> possibility).
>
> From the get-go, I'm not sure that it's desirable to take away the
> opportunity for users to install a different even filter at the QApp
> level....
> But I took your code and added logic to do this kind of event (which is
> only a single event, quite easy). My "code" also supports an emacs-like
> sequence of one mouse event (with or without modifier keys), followed by
> a single key (as in your code). one keyboard. But I'm unsure whether we
> want to have the GUI-related mouse support in the same Class as the
> keyboard shortcuts, which could apply to console applications as well
> (both QML and non-QML). First, however, I need to make it compile
> succesfully: I am (so far) unable to convert 'QEvent::Type' enum values
> into QVariant, and I'm unsure why all variables are being defined as
> QVariant in the first place (i.e., instead of specific datatypes.)
>
> I know that you busy with a new job :)) If you can assist, however,
> please advise. Same goes for everyone else - Alan? My time is relatively
> unlimited for the next week, but I'm an incompetent programmer.
>
>> The signal gets emitted when the sequence has been pressed. The
>> current implementation as written on the blog post in [1] works like a
>> charm in my case :)
>>
>> [1] http://kdeblog.mageprojects.com/2012/12/07/application-wide-shortcuts-in-qml-this-time-without-qshortcut/
>>
>

I don't know why everything is QVariant based, but i "might" know how
to get an enum in a QVariant. Would Q_DECLARE_METATYPE(QEvent::Type)
work? Found that one here:
http://qt-project.org/forums/viewthread/6738

I haven't tested it yet..



More information about the Development mailing list