
Originally Posted by
Tanuki-no Torigava
And please look at this once again:
Did you call setFocusPolicy?
Guys read the docs carefully! First ignore() and accept() are not necessary! and setFocusPolicy is also not required. The user can activate the widget himself using the mouse or tab...
So a simple implementation would be:
// eats space
void WaveWidget
::keyPressEvent( QKeyEvent* pe
) {
switch( pe->key() )
{
case Qt::Key_Space:
{
qDebug() << "Space pressed";
m_wave->playSound();
}
break;
default:
break;
}
}
// just plays a sound whenever space is pressed
void WaveWidget
::keyPressEvent( QKeyEvent* pe
) {
switch( pe->key() )
{
case Qt::Key_Space:
{
qDebug() << "Space pressed";
m_wave->playSound();
}
break;
default:
break;
}
}
// eats space
void WaveWidget::keyPressEvent( QKeyEvent* pe )
{
switch( pe->key() )
{
case Qt::Key_Space:
{
qDebug() << "Space pressed";
m_wave->playSound();
}
break;
default:
QWidget::keyPressEvent(pe);
break;
}
}
// just plays a sound whenever space is pressed
void WaveWidget::keyPressEvent( QKeyEvent* pe )
{
switch( pe->key() )
{
case Qt::Key_Space:
{
qDebug() << "Space pressed";
m_wave->playSound();
}
break;
default:
break;
}
QWidget::keyPressEvent(pe);
}
To copy to clipboard, switch view to plain text mode
assuming QWidget is your base class. And such problems should be better posted in the Newbie section.
Bookmarks