大家看我一段QT代码:
bool MythSpinBox::eventFilter(QObject* o, QEvent* e)
{
(void)o;
if (e->type() == QEvent::FocusIn)
{
QColor highlight = colorGroup().highlight();
editor()->setPaletteBackgroundColor(highlight);
emit(changeHelpText(helptext));
}
else if (e->type() == QEvent::FocusOut)
{
editor()->unsetPalette();
}
if (e->type() != QEvent::KeyPress)
return FALSE;
bool handled = false;
QStringList actions;
if (gContext->GetMainWindow()->TranslateKeyPress("qt", (QKeyEvent *)e,
actions))
{
for (unsigned int i = 0; i < actions.size() && !handled; i++)
{
QString action = actions;
handled = true;
cout<<"+++cjq eventFilter action = "<<action<<endl;
if (action == "LEFT")
{
cout<<"111111111111111111111"<<endl;
return FALSE;
}
else if (action == "RIGHT")
{
cout<<"111111111111111111111"<<endl;
return FALSE;
}
else if (action == "UP")
{
if (singlestep)
setValue(value() - 1);
else
stepDown();
}
else if (action == "DOWN")
{
if (singlestep)
setValue(value() + 1);
else
stepUp();
}
else if (action == "PAGEUP")
stepDown();
else if (action == "PAGEDOWN")
stepUp();
else if (action == "SELECT")
handled = true;
else if (action == "ESCAPE")
{
cout<<"111111111111111111111"<<endl;
return FALSE;
}
else
handled = false;
}
}
return TRUE;
}
当按下LEFT 键和 ESCAPE键代码是相同的,可为什么在LEFT时可以打印出1111111111111(即LEFT事件在此处处理了),而ESCAPE时不能打印出1111111111111(ESCAPE事件没有在此处处理,交给父窗口处理了)?
我实际想要的结果是当按LEFT时不做处理,交给父窗口来处理,为什么同样的代码在ESCAPE时就可以,而LEFT时就不可以了呢?
很着急啊,谁懂啊?
[ 此帖被bigapple88在2009-12-06 17:26重新编辑 ]