[Interest] QtQuick - How to move focus away from disabled Item?

Jérôme Godbout jerome at bodycad.com
Wed Jan 28 18:04:56 CET 2015


Hi,
This may not be a direct answer but you may want to take a look at
FocusScope Qml Element:
http://doc.qt.io/qt-5/qml-qtquick-focusscope.html

Here's a good explaination about those scope:
http://doc.qt.io/qt-5/qtquick-input-focus.html

Hope this help somehow,
Jerome


On Wed, Jan 28, 2015 at 9:46 AM, Ola Røer Thorsen <ola at silentwings.no>
wrote:

> Hi,
>
> I'm having some trouble making a robust QtQuick 5.4-based application
> where I only have 4 cursor keys and a return key available as the input
> method for the user.
>
> I have various gui buttons that I can move focus between. I've set this up
> using the KeyNavigation.onXXX etc. For a simple static gui, this is fine.
>
> However I get into trouble once some buttons get disabled
> (enabled-property set to false). This is done based on external events, so
> it may happen at any time.
>
> If a button with active focus is disabled, I'm stuck. The button's focus
> property is still true, but it will not receive key events, so I cannot
> move focus to the next using the cursor keys. I'd like focus to move on to
> some other item automatically anyway.
>
> Have any of you got some recommended way of dealing with situations like
> this?
>
> I think I've spent half the development time on this application just
> making sure keyboard navigation cannot get stuck.
>
> I did not have such issues when creating similar applications with Qt
> Widgets. There the behavior is that focus moves on to another widget
> automatically if I call setEnabled(false) on a widget with current active
> focus.
>
> I've tried doing something like this in my Button item:
>
> Button {
>    id: button
>    activeFocusOnTab: true
>    function transferFocus() {
>       if(!visible || enabled)
>          return;
>       if(nextItemInFocusChain() === button)
>          return;
>       if(focus)
>          nextItemInFocusChain().focus = true;
>    }
>    onEnabledChanged: transferFocus()
> }
>
> This works OK in a smaller test application, but makes the larger
> application hang when  "nextItemInFocusChain" is called for the 20th time
> or so.
>
> Cheers,
> Ola
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150128/83ef84f9/attachment.html>


More information about the Interest mailing list