[Qt-interest] Focus on a hidden widget.
Atlant Schmidt
aschmidt at dekaresearch.com
Thu Mar 10 16:52:16 CET 2011
Expanding on what Bo said...
Remember, the widget really has to be visible so its
parent widgets all the way up the chain of parentage
must also be showing when you attempt to set focus
to that widget. Even though you called show() on
that widget, it might still not be visible if a parent
(grandparent, etc.) is still hidden.
Logically, this makes sense: you wouldn't want to have
a bunch of widgets hanging around with "pending focus
should they become visible"; it would create a lot of
ambiguity about which widget would *REALLY GET* the focus
if a bunch of them suddenly became visible. Instead, the
rule is simple: you can only assign focus to a widget
that is currently really truly being shown.
Atlant
-----Original Message-----
From: qt-interest-bounces+aschmidt=dekaresearch.com at qt.nokia.com [mailto:qt-interest-bounces+aschmidt=dekaresearch.com at qt.nokia.com] On Behalf Of Bo Thorsen
Sent: Thursday, March 10, 2011 01:17
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] Focus on a hidden widget.
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
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.
Thank you.
Please consider the environment before printing this email.
More information about the Qt-interest-old
mailing list