How do you use existing (but not basic) Qml types (for example Rectangle, Buttons, etc.) as properties for custom C++ - defined types?
-
Seems like a stupid question, but I have not found anything about this. There is a page in the documentation that shows how to use custom types as properties for C++ - defined types, but what do I do if I want, for example, a Rectangle as a background for an Item?
-
Hi @mahlersand
If I understood you correctly, you cant useRectangle
,Buttons
directly inside C++ defined types as they don't have a public C++ API's. if you are usingQQuickPaintedItem
then you can draw your own rectangle using variousQPainter
methods. -
@p3c0 Yes, it's just that i wanted to avoid that, as i wanted the
Rectangle
to be accessible and modifiable from within the QML code. That is currently only (theoretically) possible through the private classes#include <QtQuick/5.5.0/QtQuick/private/qquickrectangle_p.h>
, but it is not really working. -
@mahlersand Using private classes is not recommended as its implementation may change from version to version. The best would be to use
QQuickPaintedItem
and create your own custom types.