How to implement the movement of focus only by the direction key
The situation is ，the environment is in the embedded product，so no mouse can be used。There are only four direction keys to move the focus between the controls in the widget, and a Enter key to simulate pressing on the focus control.
And I have other widget like this,so I firstly create a stackedWidget ,then create a base widget class to be inherited.Depend on the operation of the user,the widget in the stackedWidget is deleted,and ,a new widget created and added in the stackedWidget .I written a loop to install a eventFilter on the all controls in the constructor of the base widget class .when the direction key pressed,the eventFilter will chang the focus control by the direction key.The eventFilter code is below:
bool KeyManage::eventFilter(QObject obj, QEvent event)
if(event->type() == QEvent::KeyPress)
keyEvent = (QKeyEvent)event;
if(Qt::Key_Up == keyEvent->key()||
Qt::Key_Right == keyEvent->key()||
Qt::Key_Left == keyEvent->key()||
Qt::Key_Down == keyEvent->key())
else if (Qt::Key_Return == keyEvent->key())
When a widget created and added in the stackedWidget,the initial focus control is setted,and all the controls install the eventFilter in the base class,but now I met a problem:when the program started,the first widget have effect after ker press.But From the second widget,there is no effect after key press unless first press a button(please attention,only the button ,not label and other type control in the widget) with mouse .When I press on the other part of the screen then press the widget (all the area of the widget,not only the button,different with the case before),the key direction will do right.So please give me some idea to solve the problem ,or give me a new method to implement the movement of focus .
Thank you !