[Qt-interest] FW: keyPressEvent() confusion with dead keys/accents correctly

Atlant Schmidt aschmidt at dekaresearch.com
Wed Sep 29 21:38:25 CEST 2010


Nikos:

  (Copied to the list)

> I'm not sure I understand what you mean.
> Qt only deals with key press and key release events.

  Ahh, yes, it's coming back to me now. The work I was
  doing was in the glue between Symbian, Qt, and JavaScript
  and you're right, it was:

    Symbian:     KeyDown,  KeyRepeat, [KeyRepeat...], KeyUp
    Qt:          KeyPress,            [KeyPress...],  KeyRelease
    JavaScript:  KeyPress, Key,       [Key...]        KeyRelease


  As Emily Litella says, "Nevermind!"

                        Atlant

-----Original Message-----
From: Nikos Chantziaras [mailto:realnc at arcor.de]
Sent: Wednesday, September 29, 2010 13:34
To: Atlant Schmidt
Subject: Re: [Qt-interest] keyPressEvent() confusion with dead keys/accents correctly

I'm not sure I understand what you mean.  Qt only deals with key press
and key release events.


On 09/29/2010 08:27 PM, Atlant Schmidt wrote:
> Nikos:
>
>    Are you sure you're looking at the key data from the
>    Key event and not KeyPress or KeyRelease events? Those
>    "enclosing" events are likely to be raw keys whereas
>    the Key event will likely contain the final "cooked"
>    keycode.
>
>    (But it's been a few months since I last dealt with
>    this so my memory may be faulty.)
>
>                            Atlant
>
>
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Nikos Chantziaras
> Sent: Wednesday, September 29, 2010 13:01
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] keyPressEvent() confusion with dead keys/accents correctly
>
> Basically, I ran across this exact same problem:
>
> http://www.qtcentre.org/threads/4653-Handling-of-dead-keys-in-keyPressEvent%28%29
>
>     I want to capture key presses, including dead keys.
>     So for instance, if you press ~ and afterwards n,
>     you get ñ (at least on a Spanish keyboard layout).
>
>     When I reimplement keyPressEvent() in my widget, I
>     get however always the ~ and n separately. I would
>     rather get only one keyPressEvent() with the
>     complete character.
>
> On his system it was a keyboard layout problem.  However, I don't have
> keyboard layout problems and other Qt applications work correctly in
> this regard (I can input accents correctly in Creator for example, or
> any demo app that comes with Qt, or any other Qt app I have installed on
> my system, including the whole of KDE.)  So it seems I'm doing it wrong
> in my keyPressEvent()?
>
> My keyPressEvent() receives dead keys.  AFAIK, it shouldn't receive them
> in the first place, because when compiling the application for Windows,
> it doesn't.  It does only on Linux.  Furthermore, if I ignore dead keys
> with something like:
>
>     if (e->key()>= Qt::Key_Dead_Grave&&  e->key()<= Qt::Key_Dead_Horn) {
>         QScrollArea::keyPressEvent(e);
>         return;
>     }
>
> then I get rid of the problem of printing dead keys, but the next key
> event I get still does not contain the correct, accented character in
> its e->text().  It contains the unaccented one.
>
> Turning on key compression with setAttribute(Qt::WA_KeyCompression) does
> not help.
>
> Studying the source code of QTextEdit and its keyPressEvent()
> implementation didn't turn up anything useful either.
>
> My keyPressEvent() implementation can be simplified to this:
>
>     if (e->text().isEmpty() || !e->text().at(0).isPrint()
>         || (e->key()>= Qt::Key_Dead_Grave
>             &&  e->key()<= Qt::Key_Dead_Horn))
>     {
>         QScrollArea::keyPressEvent(e);
>         return;
>     }
>
>     qDebug()<<  e->text()
>
> In this implementation, qDebug will *never* print a "ñ".  It's always
> just "n".
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.
>
> Thank you.
>
> Please consider the environment before printing this email.
>


This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.

Thank you.

Please consider the environment before printing this email.




More information about the Qt-interest-old mailing list