| Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
Hi, Is there any way to figure out if a QKeyEvent matches a QKeySequence constructed from a plain text? Or in other words, is there a way of testing if an QKeyEvent matches for instance "Ctrl+F7" ? -=Børge
Børge Austvold said the following on 17.10.2007 13:06:
> Hi,
>
> Is there any way to figure out if a QKeyEvent matches a QKeySequence
> constructed from a plain text? Or in other words, is there a way of testing
> if an QKeyEvent matches for instance "Ctrl+F7" ?
Have a look at
http://doc.trolltech.com/4.3/qkeysequence.html#QKeySequence-3
and http://doc.trolltech.com/4.3/qkeysequence.html#matches
--
[ signature omitted ]
Attachment:
signature.asc
Description: OpenPGP digital signature
Marius Storm-Olsen wrote: > Børge Austvold said the following on 17.10.2007 13:06: >> Hi, >> >> Is there any way to figure out if a QKeyEvent matches a QKeySequence >> constructed from a plain text? Or in other words, is there a way of >> testing if an QKeyEvent matches for instance "Ctrl+F7" ? > > Have a look at > http://doc.trolltech.com/4.3/qkeysequence.html#QKeySequence-3 > and http://doc.trolltech.com/4.3/qkeysequence.html#matches > The Qt Jambi docs for this are: http://doc.trolltech.com/qtjambi-4.3.1_01/com/trolltech/qt/gui/QKeySequence.html http://doc.trolltech.com/qtjambi-4.3.1_01/com/trolltech/qt/gui/QKeySequence.html#matches(com.trolltech.qt.gui.QKeySequence) - Gunnar
Hi,
Does that mean that I can create an QKeySequence like this :
QKeyEvent event ...
QKeySequence s1 = new QKeySequence(event..modifiers().value(),
event.key());
QKeySequence s2 = new QKeySequence("Ctrl+F7");
and use it like this
s2.matches(s1)
?
-=Børge
"Gunnar Sletta" <gunnar@xxxxxxxxxxxxx> wrote in message
news:4715F214.7010603@xxxxxxxxxxxxxxxx
> Marius Storm-Olsen wrote:
>> Børge Austvold said the following on 17.10.2007 13:06:
>>> Hi,
>>>
>>> Is there any way to figure out if a QKeyEvent matches a QKeySequence
>>> constructed from a plain text? Or in other words, is there a way of
>>> testing if an QKeyEvent matches for instance "Ctrl+F7" ?
>>
>> Have a look at
>> http://doc.trolltech.com/4.3/qkeysequence.html#QKeySequence-3
>> and http://doc.trolltech.com/4.3/qkeysequence.html#matches
>>
>
> The Qt Jambi docs for this are:
>
> http://doc.trolltech.com/qtjambi-4.3.1_01/com/trolltech/qt/gui/QKeySequence.html
> http://doc.trolltech.com/qtjambi-4.3.1_01/com/trolltech/qt/gui/QKeySequence.html#matches(com.trolltech.qt.gui.QKeySequence)
>
> -
> Gunnar
Hi Again,
The above code worked if I changed s2 to new QKeySequence("Ctrl+,F7") I
guess this is probably a bug either in the documentation or the code...
-=Børge
"Børge Austvold" <bna@xxxxxxxxxxx> wrote in message
news:ff4v05$tf3$1@xxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> Does that mean that I can create an QKeySequence like this :
>
> QKeyEvent event ...
> QKeySequence s1 = new QKeySequence(event..modifiers().value(),
> event.key());
> QKeySequence s2 = new QKeySequence("Ctrl+F7");
>
> and use it like this
>
> s2.matches(s1)
>
> ?
>
> -=Børge
>
>
>
> "Gunnar Sletta" <gunnar@xxxxxxxxxxxxx> wrote in message
> news:4715F214.7010603@xxxxxxxxxxxxxxxx
>> Marius Storm-Olsen wrote:
>>> Børge Austvold said the following on 17.10.2007 13:06:
>>>> Hi,
>>>>
>>>> Is there any way to figure out if a QKeyEvent matches a QKeySequence
>>>> constructed from a plain text? Or in other words, is there a way of
>>>> testing if an QKeyEvent matches for instance "Ctrl+F7" ?
>>>
>>> Have a look at
>>> http://doc.trolltech.com/4.3/qkeysequence.html#QKeySequence-3
>>> and http://doc.trolltech.com/4.3/qkeysequence.html#matches
>>>
>>
>> The Qt Jambi docs for this are:
>>
>> http://doc.trolltech.com/qtjambi-4.3.1_01/com/trolltech/qt/gui/QKeySequence.html
>> http://doc.trolltech.com/qtjambi-4.3.1_01/com/trolltech/qt/gui/QKeySequence.html#matches(com.trolltech.qt.gui.QKeySequence)
>>
>> -
>> Gunnar
>
Børge Austvold said the following on 17.10.2007 14:25:
> Hi,
>
> Does that mean that I can create an QKeySequence like this :
>
> QKeyEvent event ...
> QKeySequence s1 = new QKeySequence(event..modifiers().value(),
> event.key());
> QKeySequence s2 = new QKeySequence("Ctrl+F7");
>
> and use it like this
>
> s2.matches(s1)
More like:
QKeySequence s1 = new QKeySequence(event.modifiers().value() + event.key());
QKeySequence s2 = new QKeySequence("Ctrl+F7");
s1.matches(s2)
Note: The documentation states that
"Returns NoMatch if seq is shorter.", where 'seq' here refers to the parameter of matches().
This means that you always want to have the sequence you're looking for as the parameter, and not the object for the function call. Since, you want to get PartialMatch return value when a keysequence in incomplete.
If you use s2.matches(s1), you won't get that.
Of course, in your case it doesn't really matter, since you don't handle multiple keysequences. So, for your case you might as well just compare
if (event.modifiers().value() + event.key() == Qt::CTRL + Qt::Key_F7)
instead of going through QKeySequence. Of course, using QKeySequence is useful if you plan on translating your application, since QKeySequence allows for creating the keysequence based on stings, like you did above. But then you need to wrap it in tr(), so:
QKeySequence s1 = new QKeySequence(event.modifiers().value() + event.key());
QKeySequence s2 = new QKeySequence(tr("Ctrl+F7"));
s1.matches(s2)
--
[ signature omitted ]
Attachment:
signature.asc
Description: OpenPGP digital signature
Hi there, Thanks for the input and feedback. This is used in an curses-like application used inside a QGraphicsView to add shortcuts to text based menus. The reason for the text representation of the key sequence is that it will be rendered in the text menu like Cut Ctrl-X etc... -=Børge "Marius Storm-Olsen" <marius@xxxxxxxxxxxxx> wrote in message news:47160A43.2070503@xxxxxxxxxxxxxxxx