使用 PyQt4 扩展 QML
我想仅使用 Python 编写 QML 扩展。我知道如何在 C++ 中执行此操作,但不知道如何在 Python 中执行此操作。这可能吗?这是我正在寻找的东西的模糊想法。
class NewToQML(QObject):
Q_PROPERTY(int root READ num WRITE setNum NOTIFY numChanged REVISION 1)
在 test.qml 中:
import MyQmlAdditions 1.0
NewToQML {
num: 7;
}
[编辑] 我想使用这个 QML 添加来完成例如当鼠标位于图形对象上时更改光标(NewToQML)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不久前找到了答案 关于 nabble 由 Phil Thompson-5 回答,并由 Giovanni Bajo 进行了很好的解释/推理。
简短回答:从 4.7 及更早版本开始,PyQt 不支持 qmlRegisterType。
但是,PySide 确实具有此功能,如此处所示。
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.
如果您使用 PyQt 安装了示例和演示,则 Minehunt 演示提供了 QML 示例。如果您尚未安装,请下载 PyQt4 源 并查看
示例/演示/声明性/minehunt
。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
.