[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Widget Focus
From:       Steven Sroka <sroka.steven () gmail ! com>
Date:       2011-06-22 23:55:43
Message-ID: BANLkTin_pLXchvieoQfsGXd3pt1NtGhH7Q () mail ! gmail ! com
[Download RAW message or body]

>On 22 June 2011 03:29, Kevin Funk <krf@gmx.de> wrote:
> Wednesday 22 June 2011, Steven Sroka <sroka.steven@gmail.com>:
>> Is there any way to set focus to manually a widget when a window opens? I
>> used QRadioButton::setFocus(Qt::ActiveWindowFocusReason), but it doesn't
>> help, the first widget placed on the window always has focus.

Thank you everyone. I simply added QRadioButton::setFocus() at the end
of the block of code.

You would know this better than me, is
QTimer::singleShot/QMetaObject::invokeMethod preferable in this
scenario?
I don't think it is guaranteed that each line of code is run after the
previous line is successfully completed, therefore I might need to
ensure the program only calls QRadioButton::setFocus() after the
widgets are created and placed.
Would the event loop help in this scenario? Then again it is probably
overkill, but it is an interesting situation.

>
> Hey,
>
> Do you call setFocus *after* creating/layouting the widgets? Constructing
> other widgets afterwards will change the keyboard focus, so be sure to make
> this call last.
>
> Other than, it might help to use the event loop for calling the setFocus()
> slot on a widget, e.g.:
> QTimer::singleShot(0, widget, SLOT(setFocus()));
>
> This ensures that the widget(s) is/are fully constructed before receiving the
> focus activation.
>
> Hope this helps,
>
> Greets
>
> --
> Kevin Funk
>
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic