[FIXED]Qt key event doesn't work

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums

[FIXED]Qt key event doesn't work

Postby Virion » Fri Feb 12, 2010 6:27 pm

Code: Select all
void QIrrlichtWidget::keyReleaseEvent(QKeyEvent *event)
{
    if ( device != 0 )
    {
        switch(event->key())
        {
        case Qt::Key_W:
            {
                std::cout<< "W button" << std::endl;
            }
        break;
        default:
        return;
        }
    }
}


Weird, mouse event works but not key event. What is wrong with my code? Anyone using Qt here?

For mouse, it works:
Code: Select all
void QIrrlichtWidget::mouseReleaseEvent(QMouseEvent* event)
{
    if ( device != 0 )
    {
        switch (event->button())
        {
        case Qt::LeftButton:
            {
                std::cout<< "left button" << std::endl;
            }
            break;
        case Qt::RightButton:
            {
                std::cout<< "right button" << std::endl;
            }
            break;
        default:
            return; // Cannot handle this mouse event
        }
    }
}
Last edited by Virion on Fri Feb 12, 2010 7:57 pm, edited 1 time in total.
User avatar
Virion
 
Posts: 2102
Joined: Mon Dec 18, 2006 5:04 am
Location: Malaysia

Postby Virion » Fri Feb 12, 2010 7:57 pm

Problem fixed. Have to grab the keyboard input when initialize the widget class

QIrrlichtWidget::QIrrlichtWidget( QWidget *parent )
: QWidget(parent)
{
// Wait for the init() call
device = 0;

// Default to Open GL
driverType = irr::video::EDT_OPENGL;

this->grabKeyboard();
}
User avatar
Virion
 
Posts: 2102
Joined: Mon Dec 18, 2006 5:04 am
Location: Malaysia

Postby Escen » Fri Feb 12, 2010 10:27 pm

Hi Virion,

I was not using Key-event yet, bud notes that it was not working either.

Thanks for figure this out.
Escen
Competition winner
 
Posts: 132
Joined: Sun Jul 19, 2009 11:27 am

Postby Virion » Sat Feb 13, 2010 5:20 am

Escen wrote:Hi Virion,

I was not using Key-event yet, bud notes that it was not working either.

Thanks for figure this out.

I'm glad it helps. :)
User avatar
Virion
 
Posts: 2102
Joined: Mon Dec 18, 2006 5:04 am
Location: Malaysia


Return to Game Programming

Who is online

Users browsing this forum: No registered users and 1 guest