Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Show focus highlight when open a window
I am playing with the widget focus. I want to navigate through the buttons with tab key. I put the tab order but I need to show the highlight stylesheet when I open the window in the first button.
I tried with ui->button->setFocus() in the constructor but qt doesn't highlight it.
How can I do it?
Thank you very much!
As docs says
"Be aware that if the widget is hidden, it will not accept focus until it is shown."
so you cannot do it in ctor as its hidden there.
You can use the forms ShowEvent.
@mrjj The button isn't hidden. I tried with the showEvent but it doesn't work. The problem is the first time, when I push tab button, the next button highlights correctly. The first button doesn't highlight at first time.
Well, the button is hidden in the constructor as it not yet shown. That was my main point.
Ok, it normally works fine with showEvent.
did you try setFocus with Qt::TabFocusReason ?
@mrjj I have tried it but it doesn't work.
when you say dont work. what does it mean.
the button does get focus but the stylesheet is not triggering
or in which "doesn't work."
@mrjj It's always the same problem. The button has the focus, but doesn't show the focus stylesheet
so either it don't really have the focus or there is a bug in stylesheet handling or in user code.
Do you have a minimal example showing this behavior?