[Development] QAction-like API for QML

Martin Jones martin.jones at qinetic.com.au
Tue Dec 11 06:05:51 CET 2012


On Tue, Dec 11, 2012 at 1:39 PM, Alan Alpert <416365416c at gmail.com> wrote:
> QAction served widgets well as an abstraction for an "Action" which is
> exposed to the UI in a platform specific manner. This was shared
> between menus and toolbars and some other things. I think we'll need
> something similar for QML, so that the QtQuick controls can provide
> platform styled menus, toolbars, and perhaps some other things. This
> is particularly important for those working on the modern
> cross-platform challenge of scaling to different devices - we need the
> actions generic enough to fit a phone's itty bitty little menu as well
> as the unifed menubar that spans over 2000px on today's Macs.
>
> QAction can't be used straight, it's in the QtWidgets library (and has
> QWidget* in the public API - it's not moving), so we need a new API
> for this. Ideally though it would be fairly similar to allow for
> developers to easily move to it, maybe to make it easier to integrate
> the two better later. There was a discussion at Dev Days, here's what
> we came up with initially. Note that I'm using QML to prototype the
> API ;).
>
> Action type:
> QtObject {
>     property string text
>     property url imageSource
>     property string shortcut
>     property bool checkable: false
>     property bool checked: false
>     signal triggered(bool checked)
> }

Where are you proposing this goes?  To me it looks like a candidate
for Qt Components (or is it Controls now).

[snip]

>
> In addition to the API review of that prototype, the following
> questions that come to mind:
> ActionGroup could be dropped in favor of adding a subactions property
> to Action. But Aaron brought up a good point that this makes it a lot
> more discoverable how to implement nested menus/actions. Is it worth
> it to split up Action/ActionGroup?

I don't like the idea of subactions.  Nested menus are the only case I
can think of that uses it, but its always there in the API.

> Given that that UIs from the '90s can be implemented with widgets
> still, are exclusive and checkable used by modern UIs? i.e. Is it
> worth putting them in a new API?

Probably not very common in menus now, but an action is also useful
for checkboxes and they are quite checkable.

> The QMenu API allows for adding menu separators too, but I haven't
> seen those in apps for a while. Is it worth adding another type or
> flag to integrate separators into the Action API?

A separator needs none of the API present in an Action.  They are unrelated.

> In that example all the ActionGroups set collapsible to true, but that
> could just be because that's the functionality the example is
> demonstrating. ActionGroups can also be used for grouping actions and
> in that case you may not want collapsible. Should collapsible be true
> by default?

"collapsible" is another property which seems to be quite tied to a
menu's implementation.  What is the overall goal of these types?  Are
they to be added somewhere quite core, e.g. QtQuick, or are they to be
added to Components?

Br,
Martin.



More information about the Development mailing list