Qt-interest Archive, October 2006
problem for not trapping arrow keys
Message 1 in thread
I made my custom QMainWindow composed of menu,toolbar,status and custom QGraphicsView object named *frontEnd; then implemented virtual function: void keyPressEvent(QKeyEvent *event) to obtain keyPress information. But after execution, I can trap keyPress information except arrow keys including Key_Up, Key_Down, Key_Left, Key_Right. Below are codes of constructor of my QMainWindow and keyPressEvent. Please help me, Thanks!
=====constructor======
MyMainWindow ::
MyMainWindow(QGraphicsScene &c,QWidget *parent, Qt::WindowFlags f)
:QMainWindow(parent,f),canvas(c)
{
createActions();
createMenus();
createToolBars();
createStatusBar();
myActions.insert( Qt::Key_Left,myLeft);
myActions.insert( Qt::Key_Right,myRight);
myActions.insert( Qt::Key_Down,myDown);
myActions.insert( Qt::Key_Up,myUp);
myActions.insert( Qt::Key_Space, Shoot);
myActions.insert( Qt::Key_N, NewGame);
frontEnd=new MyGameView(canvas,this);
frontEnd->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
frontEnd->setFocusPolicy( Qt::StrongFocus );
setFixedSize(700,550);
setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
setCentralWidget(frontEnd);
frontEnd->setFocus();
}
========Event handle======
void MyMainWindow::keyPressEvent(QKeyEvent *event)
{
qDebug("presskeyEvent has occured, and type is ");
event->accept();
return;
}
---------------------------------
Do you Yahoo!?
Get on board. You're invited to try the new Yahoo! Mail.