Problem in getting focus?
-
In my program i am reimplementing key press event but it is not getting called in pressing the arrow key
@void slider::keyPressEvent (QKeyEvent *event)
{
qDebug ()<<"keypress";
if (slider_mode) {
if (event->key () == Qt::Key_Left) {
event->accept ();thumb_pos_groove = thumb_pos_groove - 1; calcNewValue (); emit sliderMoved (value_pos_hori); this->repaint (); } else if (event->key () == Qt::Key_Right){ event->accept (); thumb_pos_groove = thumb_pos_groove + 1; calcNewValue (); emit sliderMoved (value_pos_hori); this->repaint (); } } else { if (event->key () == Qt::Key_Up) { event->accept (); thumb_pos_groove = thumb_pos_groove - 1; calcNewValue (); //emit sliderMoved (value_pos_verti); this->repaint (); } else if (event->key () == Qt::Key_Down){ event->accept (); thumb_pos_groove = thumb_pos_groove + 1; calcNewValue (); //emit sliderMoved (value_pos_verti); this->repaint (); } }
}@
. I am not able to find what is the problem . -
[quote author="pratik041" date="1321346642"]no because i am always setting slider mode .[/quote]
Apologize me for insisting, but setting slider_mode will result in avoiding the execution of the key.up/down handling. So if you are seeing the debug message but nothing happens when you push up/down then it is the boolean flag interfering with your code. Otherwise does the code for the up key work? Could you check exactly what key event is generated when you push the down key?
-
If I get it right, the problem seems to be that the spinbox has the focus and not the slider. If that is the case, my first thoughts will be to either
- give back the focus to the slider after any change in the spinbox
- propagate the keypress event from the spin box to the slider (so implement a keyevent listener in the spinbox too and send the event to the slider).
But in both cases, please note that any widget in the window will have to do the same, or your changes will be vanished from adding new widgets. So, if this is the problem, I suggest to implement the event listener in the main widget and propagate it to the slider.
Someone could have better suggestions.