[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    Re: QActions in QML
From:       Daker Fernandes Pinheiro <dakerfp () gmail ! com>
Date:       2012-10-29 12:26:59
Message-ID: CAHhpqga1itrATjQSCZC81XYN3_aC-=dBagntZgbw3O6_s93f6w () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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

> On Mon, Oct 29, 2012 at 1:33 AM, Daker Fernandes Pinheiro
> <dakerfp@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=C3=BCgler <sebas@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 ent=
ry
> >> 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@kde.org
> >> https://mail.kde.org/mailman/listinfo/plasma-devel
> >
> >
> >
> > _______________________________________________
> > Plasma-devel mailing list
> > Plasma-devel@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@kde.org
> https://mail.kde.org/mailman/listinfo/plasma-devel
>


Br,

Daker Fernandes Pinheiro
http://codecereal.blogspot.com

[Attachment #5 (text/html)]

2012/10/28 Aleix Pol <span dir="ltr">&lt;<a href="mailto:aleixpol@kde.org" \
target="_blank">aleixpol@kde.org</a>&gt;</span><br><div \
class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex">

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

  <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"> <span class="HOEnZb"><font color="#888888"><br>
Aleix<br>
</font></span><div class="HOEnZb"><div \
class="h5">_______________________________________________<br> Plasma-devel mailing \
list<br> <a href="mailto:Plasma-devel@kde.org">Plasma-devel@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/plasma-devel" \
target="_blank">https://mail.kde.org/mailman/listinfo/plasma-devel</a><br> \
</div></div></blockquote></div><br><br>Br,<br><br>Daker Fernandes Pinheiro<br><a \
href="http://codecereal.blogspot.com" \
target="_blank">http://codecereal.blogspot.com</a><br><br>



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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic