You need to subclass the widget and override the handler for events (s) that should display a tooltip. In the handler, create a QHelpEvent type QEvent::ToolTip and run it in the event loop. Finally, call the parent source handler to do what it originally intended.
So specifically for focusing on the button would be
class MyButton : public QPushButton { virtual void focusInEvent(QFocusEvent *) { if(evt->gotFocus()) { QPoint pos(0,0); QHelpEvent* help = new QHelpEvent( QEvent::ToolTip,pos,this->mapToGlobal(pos)); QCoreApplication::postEvent(this,help); } QPushButton::focusInEvent(evt); } }
For visibility, you override
void QWidget::showEvent(QShowEvent * event);
and execute the same code. You need to adjust the relative pos to your taste, because initially the hint depends on the position of the mouse, which you do not have here. Also keep very tight control so that your widgets are focused and / or visible. By default, something is constantly focused, so you will get tooltips everywhere.
source share