[Qt-interest] Focus on a hidden widget.

Malyushytsky, Alex alex at wai.com
Fri Mar 11 04:24:22 CET 2011


According to my impression you can’t simply call setFocus() right after show().
What you can do is to make sure setFocus is called after widget is displayed ( as a result  of show ).

Few ways come in mind:

 -Put setFocus in custom slot ( for example myslot() )
Replace setFocus( … ) call with
QTimer::singleShot(0, this, SLOT(myslot()));

myslot() will be called when event loop take care about all events .

-Another possible way to handle it (never tried but logically should work )
 - is to enforce application event loop  to process events before setFocus:

show() ;
QCoreApplication::processEvents();
setFocus(…)


Alex





From: qt-interest-bounces+alex=wai.com at qt.nokia.com [mailto:qt-interest-bounces+alex=wai.com at qt.nokia.com] On Behalf Of Kahola.g
Sent: Wednesday, March 09, 2011 7:58 AM
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] Focus on a hidden widget.

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?

--
kahola


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”

“Please consider our environment before printing this email.”


More information about the Qt-interest-old mailing list