Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, August 2006
QKeyEvent::key() for numerical keys


Message 1 in thread

Dear List,

In a keyPressEvent handler for a QWidget, I was trying to check for number
keys via

    ( e->key() >= Qt::Key_0 ) && ( e->key() <= Qt::Key_9 )

but that was not ever returning TRUE.  So I put in this statement:

    qDebug( "keyPressEvent( %d ), with Key_0==%d and Key_9==%d",
             e->key(), Qt::Key_0, Qt::Key_9 );

and when I press number keys, I get debug output like this:

    keyPressEvent( 1 ), with Key_0==48 and Key_9==57
    keyPressEvent( 2 ), with Key_0==48 and Key_9==57
    keyPressEvent( 3 ), with Key_0==48 and Key_9==57
    keyPressEvent( 4 ), with Key_0==48 and Key_9==57
    keyPressEvent( 5 ), with Key_0==48 and Key_9==57

Why is number key 1 generating a key event with e->key() == 1 instead of
e->key() == Qt::Key_1 == 49?  Anyone else hit this problem?  Am I doing
something wrong or have I found a Qt bug (Qt 4.1.4 on Mac OS 10.4.7)?

Nathan


--
 [ signature omitted ] 

Message 2 in thread

As an update, upon successfully completing my WinXP build, I find that this
issue only happens on the Mac.  The WinXP version seems to get the key event
numbers you'd expect (0 gives Qt::Key_0, not 0).

Since no one has responded, I guess I'll file a bug report.

Nathan


On 8/1/06 10:18 AM, "Nathan Carter" <ncarter@xxxxxxxxxxx> wrote:

> 
> Dear List,
> 
> In a keyPressEvent handler for a QWidget, I was trying to check for number
> keys via
> 
>     ( e->key() >= Qt::Key_0 ) && ( e->key() <= Qt::Key_9 )
> 
> but that was not ever returning TRUE.  So I put in this statement:
> 
>     qDebug( "keyPressEvent( %d ), with Key_0==%d and Key_9==%d",
>              e->key(), Qt::Key_0, Qt::Key_9 );
> 
> and when I press number keys, I get debug output like this:
> 
>     keyPressEvent( 1 ), with Key_0==48 and Key_9==57
>     keyPressEvent( 2 ), with Key_0==48 and Key_9==57
>     keyPressEvent( 3 ), with Key_0==48 and Key_9==57
>     keyPressEvent( 4 ), with Key_0==48 and Key_9==57
>     keyPressEvent( 5 ), with Key_0==48 and Key_9==57
> 
> Why is number key 1 generating a key event with e->key() == 1 instead of
> e->key() == Qt::Key_1 == 49?  Anyone else hit this problem?  Am I doing
> something wrong or have I found a Qt bug (Qt 4.1.4 on Mac OS 10.4.7)?
> 
> Nathan
> 
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

-- 
 [ signature omitted ]