[Qt-qml] Why FocusChange is never emitted?

Gregory Schlomoff gregory.schlomoff at gmail.com
Wed Aug 4 13:49:36 CEST 2010


Hello everyone,

We are using the latest version of Qt 4.7 from the repository, and the
focus works very well, in a very intuitive way, much better than with
the old "wantsFocus".

Except for one thing: onFocusChanged never gets called.

Sure, we could use onActiveFocusChanged instead, and indeed, in most
cases, that's what we need. But there are some edge cases when you
actually want onFocusChanged.

Example: we have an app with a left panel and a right panel. Each
panel is inside a FocusScope. We use focus to track wich item should
be highlighted in the left panel.  To do that, we simply have a
"highlighted" State on each item that is activated when they get the
focus. It should work, but it doesn't, because focusChanged is not
emitted, so the states don't get updated. If instead whe bind our
State to activeFocus, it works, but the highlight will disappear as
soon as an item from the right side gets active focus.

Example:

Rectangle {
 color: "grey"
 State {name: "highlighted; when: activeFocus  // works, but will lose
the highlight
   PropertyChange [...]
}

Rectangle {
 color: "grey"
 State {name: "highlighted; when: focus  // is what we need, but
doesn't gets notified of changes
   PropertyChange [...]
}


What are your thoughts on this? Is there a reason
for focusChanged not to be emitted?

Thanks!

Greg



More information about the Qt-qml mailing list