문제

I would like to write a QML Extension using only Python. I know how to do this in C++, but not in Python. Is this even possible? Here's a vague idea of what I'm looking for.

class NewToQML(QObject):
    Q_PROPERTY(int root READ num WRITE setNum NOTIFY numChanged REVISION 1)

And in test.qml:

import MyQmlAdditions 1.0
NewToQML {
    num: 7;
}

[edit] I would like to use this QML addition to accomplish for instance changing the cursor when the mouse is over the graphical object (NewToQML).

도움이 되었습니까?

해결책

I found the answer a while back on nabble answered by Phil Thompson-5 with a good explanation/reasoning following by Giovanni Bajo.

Short answer: PyQt does not support qmlRegisterType as of 4.7 and earlier versions.

However, PySide does have this functionality as shown here.

다른 팁

If you installed the examples and demos with PyQt, the Minehunt demo provides a QML example. If you don't have it installed, download the PyQt4 source and look in examples/demos/declarative/minehunt.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top