There are two approaches:
In Qt terms, you'd like to give slider the focus. Widgets have the
setFocus
method, so you need to callslider->setFocus(Qt::OtherFocusReason)
.Since you want the slider to get focus whenever the underlying window has focus, you need to put the
setFocus
call in your implementation offocusInEvent
for the parent widget.You can forward the key events from the underlying widget to the slider. In the parent widget, reimplement
keyPressEvent
andkeyReleaseEvent
. When the desired keys are detected, forward them to the slider:// same for keyReleaseEvent! void MyWindow::keyPressEvent(QKeyEvent * ev) { if (ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Down) { slider->event(ev); } }