[Development] QAction-like API for QML

Alan Alpert 416365416c at gmail.com
Tue Dec 18 20:35:10 CET 2012


On Tue, Dec 18, 2012 at 11:26 AM, Shawn Rutledge
<shawn.t.rutledge at gmail.com> wrote:
> On 18 December 2012 19:35, Alan Alpert <416365416c at gmail.com> wrote:
>> How is this going to work? If no iconSource or imageSource exists on
>> the Action then the delegate in QtQuickControls uses
>> "image://icons/<action-name>.png"?
>
> Yes that's what I was thinking.
>
> Pros:
> - after you name the action, you don't repeat yourself (the action
> name is part of the icon filename)
> - don't need to worry about the exact path to find the icon; that's an
> application-wide issue, not something to specify as part of each
> action
> - makes it clear an action is abstract, so maybe no qualms about
> pre-creating them in C++, because there's nothing that looks like view
> functionality
> - the naming convention exists already on Linux
> (/usr/share/icons/theme-name/32x32/actions/*.png for example)
> - the image provider could still reuse QIcon by having its own
> QHash<QString, QIcon> m_iconCache or something like that
> - most of the time you can avoid giving an iconSource at all.  If you
> do that in QML, then I suppose the image provider will have to use
> QIcon to generate the other sizes and modes?
>
> Cons:
> - if we don't put the icon in the action, is it even possible to
> specify icons for different sizes and modes in QML?  or are you just
> stuck with a fixed icon image, or the auto-generated variants, if you
> give the iconSource?

If you want more complex icon functionality, perhaps the way to do
that would be to register QIcons with the image provider? An
additional Icon type could be provided which registers new ones with
the image provider. This does separate the icon from the action
somewhat, but that's probably for the best if the icon is a complex
object with state.

I think iconSource should mean a fixed image. It's there for the case
where you don't want the delegate second-guessing you, just use this
image. You could provide it specific image provider strings of course,
but to get the delegate to choose what icon variant to use has to go
through the delegate process (which is when name is set but iconSource
isn't).

--
Alan Alpert



More information about the Development mailing list