[Qt-interest] Focus on a hidden widget.

Bo Thorsen bo at fioniasoftware.dk
Thu Mar 10 07:17:27 CET 2011


Den 09-03-2011 16:57, Kahola.g skrev:
> Hi
>
> I am facing a very peculiar problem. My widget is not getting focus.
> When i create the widget i call following two functions on it
> show()
> setFocus()
>
> this kind of code used to work. But all of a sudden i am in a situation
> where it doesnt seem to work. As I understand " if set focus is called
> on a widget that is not shown yet, it will get focus as soon as it
> becomes visible". Am i wrong here?

Did you forget to call setFocusPolicy on the widget, perhaps?

Another possibility is that you are calling setFocus too early. From the 
docs: "Be aware that if the widget is hidden, it will not accept focus 
until it is shown." You might have to wait for the widget to be shown 
before you can call setFocus.

Bo Thorsen,
Fionia Software.

-- 

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk



More information about the Qt-interest-old mailing list