QActions in QML

Daker Fernandes Pinheiro dakerfp at gmail.com
Mon Oct 29 12:26:59 UTC 2012


2012/10/28 Aleix Pol <aleixpol at kde.org>

> On Mon, Oct 29, 2012 at 1:33 AM, Daker Fernandes Pinheiro
> <dakerfp at gmail.com> wrote:
> > Sebas,
> >
> > This just worked:
> > http://paste.kde.org/584660/
> > Where QAction is
> > http://paste.kde.org/584672/
> >
> > Cheers,
> >
> > Daker Fernandes Pinheiro
> > http://codecereal.blogspot.com
> >
> >
> > 2012/10/28 Sebastian Kügler <sebas at kde.org>
> >>
> >> On Thursday, October 25, 2012 20:00:25 Aaron J. Seigo wrote:
> >> > not automatically, no. but QActions are QObjects, so you can attach to
> >> > their
> >> > signals in the QML.
> >>
> >> And it's quite wonky, for example offering a list of QActions
> >> (QDeclarativeListProperty or QList, even with the payload casted to
> >> QObjects)
> >> does not seem to work. There's one, corrupt and therefore unusable entry
> >> in
> >> the returned data in the best case, no data at all in the worst.
> >>
> >> A workaround I've found is to send a list of QActions (.name()) in a
> >> QStringList to the runtime, and offer a Q_INVOKABLE QAction*
> >> action(QString);
> >> accessor which returns a QAction* to the runtime.
> >>
> >> Your button has the following:
> >>
> >> property QtObject action
> >>
> >> onClicked: action.trigger()
> >>
> >> Then, in your delegate, you retrieve the action via the key you get in
> >> your
> >> "listmodel":
> >>
> >> delegate: ActionButton {
> >>                 action: cpppluginthing.action(modelData)
> >> }
> >>
> >> Not the most beautiful thing in the world, but it seems to work at
> least.
> >> I'm
> >> of course open to better solutions.
> >> --
> >> sebas
> >>
> >> http://www.kde.org | http://vizZzion.org | GPG Key ID: 9119 0EF9
> >> _______________________________________________
> >> Plasma-devel mailing list
> >> Plasma-devel at kde.org
> >> https://mail.kde.org/mailman/listinfo/plasma-devel
> >
> >
> >
> > _______________________________________________
> > Plasma-devel mailing list
> > Plasma-devel at kde.org
> > https://mail.kde.org/mailman/listinfo/plasma-devel
> >
>
> Wouldn't it be better to qmlRegisterType<QAction> directly?
>

That's definetely true.
I got this snippet from another project and it re-implemented trigger.
But that's not the case.


>
> Aleix
> _______________________________________________
> Plasma-devel mailing list
> Plasma-devel at kde.org
> https://mail.kde.org/mailman/listinfo/plasma-devel
>


Br,

Daker Fernandes Pinheiro
http://codecereal.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/plasma-devel/attachments/20121029/3373574b/attachment.html>


More information about the Plasma-devel mailing list