QActions in QML
Sebastian Kügler
sebas at kde.org
Sun Oct 28 22:54:16 UTC 2012
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
More information about the Plasma-devel
mailing list