[Qt-components] Key navigation

Alan Alpert 416365416c at gmail.com
Tue Jan 29 20:00:29 CET 2013


On Mon, Jan 28, 2013 at 9:43 PM, Michael Hasselmann
<michaelh at openismus.com> wrote:
> On Mon, 2013-01-28 at 11:27 -0800, Alan Alpert wrote:
>> On Mon, Jan 28, 2013 at 4:48 AM, Qi Liang <Liang.Qi at digia.com> wrote:
>> > And how about Qt::ClickFocus, I haven't touch anything about it, do
>> you have something in your mind? I guess the items with MouseArea
>> should be considered in.
>>
>> Does not apply. Mouse handling is separated out of Item so it has to
>> work on a separate level. But because key handling is in attached
>> objects on every Item (the base class) we can have keyboard focus kind
>> of like widgets (and already do). Although it is more versatile,
>> because you can manually control focus instead of setting a focus
>> policy and gaining focus only in widget supported ways.
>
> I actually like how MouseArea was split out from Item, since it easily
> allows to define item groups that can all be handled by *one* MouseArea.
> Leads to cleaner separation in code, too (models vs. event handlers).
>
> Makes me wonder why every Item processes key event. Could have also just
> been a separate EventHandler component, no?

That's basically what the attached object Keys (and KeyNavigation) is.
MouseArea needs to be separated out as an Item, because it interacts
with the visual scene on screen. Keys do not, so they could go
anywhere. It's just easier to put the attached property on an Item
than to have a separate Keys{} item in your "item hierarchy", either
users get confused by the non-visual item or there's pointless
overhead for the unused visual parts.

If we put the focus property on the attached object that would be a
complete separation. That's not a good idea though, because of the C++
integration. Custom items, like ListView or TextInput, need to be able
to directly receive and act on Key/Mouse events, and need to be in the
right focus hierarchy for the canvas. But if there was no C++, focus
could go on Keys and we've got the separate component.

--
Alan Alpert



More information about the Qt-components mailing list