From kde-devel Thu Jun 23 09:34:15 2011 From: Milian Wolff Date: Thu, 23 Jun 2011 09:34:15 +0000 To: kde-devel Subject: Re: Widget Focus Message-Id: <201106231134.15561.mail () milianw ! de> X-MARC-Message: https://marc.info/?l=kde-devel&m=130882172124975 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============1526121533==" --===============1526121533== Content-Type: multipart/signed; boundary="nextPart1910737.vjkMqCZmxp"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart1910737.vjkMqCZmxp Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Steven Sroka, 23.06.2011: > >On 22 June 2011 03:29, Kevin Funk wrote: > > Wednesday 22 June 2011, Steven Sroka : > >> 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. >=20 > Thank you everyone. I simply added QRadioButton::setFocus() at the end > of the block of code. >=20 > You would know this better than me, is > QTimer::singleShot/QMetaObject::invokeMethod preferable in this > scenario? Uhm, as it seems to work without the eventloop, everything is fine? > 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. That is not really true. Well, sure - if you call a function that creates a= =20 thread or delegates work to the eventloop than you could argue that the=20 "previous line is *not* successfully completed". But this would be a corner= =20 case and is generally not the case. Just assume that everything is done aft= er=20 you called a function. > Would the event loop help in this scenario? Then again it is probably > overkill, but it is an interesting situation. > > Hey, > >=20 > > Do you call setFocus *after* creating/layouting the widgets? Constructi= ng > > other widgets afterwards will change the keyboard focus, so be sure to > > make this call last. > >=20 > > 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())); > >=20 > > This ensures that the widget(s) is/are fully constructed before receivi= ng > > the focus activation. > >=20 > > Hope this helps, > >=20 > > Greets > >=20 > > -- > > Kevin Funk > >=20 > >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to > >> unsubscribe << =2D-=20 Milian Wolff mail@milianw.de http://milianw.de --nextPart1910737.vjkMqCZmxp Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEABECAAYFAk4DCJcACgkQDA6yEs0dE5PmYQCgr2+JDMycWqPXi1JmS6SS8HGD brQAnRZWg0LKo8+RKxKiNMTeK1GpnAb9 =I0ye -----END PGP SIGNATURE----- --nextPart1910737.vjkMqCZmxp-- --===============1526121533== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << --===============1526121533==--