Page 1 of 1

[FIXED]Qt key event doesn't work

Posted: Fri Feb 12, 2010 6:27 pm
by Virion

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
        }
    }
}

Posted: Fri Feb 12, 2010 7:57 pm
by Virion
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();
}

Posted: Fri Feb 12, 2010 10:27 pm
by Escen
Hi Virion,

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

Thanks for figure this out.

Posted: Sat Feb 13, 2010 5:20 am
by Virion
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. :)