简体   繁体   English

有什么方法可以使用 C++ 类作为 QML 组件,它可以在设计器中拖动和使用吗?

[英]Is there any way to use a C++ class as a QML component which would be available in designer to drag & use?

I have a C++ class in which I set the image path which will be available only at run time.我有一个 C++ 类,我在其中设置了仅在运行时可用的图像路径。 I want to use my class as a Custom QML component which should be available in designer tab & I can drag that & use in form editor.我想将我的类用作自定义 QML 组件,它应该在设计器选项卡中可用,我可以拖动它并在表单编辑器中使用。

You should separate logic from view.您应该将逻辑与视图分开。
For an starting point, expose your images paths as model into QML and use a ListView with a Rectangle as delegate and assign model to it.首先,将您的图像路径作为模型公开到 QML 中,并使用带有RectangleListView作为委托并为其分配模型。 Therefore you have a rectangle for each image path.因此,每个图像路径都有一个矩形。
For more information read this and this one有关更多信息,请阅读

* Please note that registering QML Component in Qt 5.15+ has been changed. *请注意,在 Qt 5.15+ 中注册 QML 组件已更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM