I think you are confusing things at different levels, and this makes this question a "difficult" question, which should be divided into smaller questions ...
Anyway:
- if you need a
QWindow that can host QtQuick 2 content , you will need a QQuickView or QQuickWindow (usually the first, more convenient, see their docs). - QtQuick2 is not a
QGraphicsView based . This is not even in QtWidgets - you cannot use any class associated with widgets or APIs. - The easiest way to bind a property of a QML element to one of the C ++ objects is to simply expose this object to the QML mechanism, and then perform the usual binding.
For instance:
class MyObject : public QObject { Q_OBJECT Q_PROPERTY(int horizontalPos READ horizontalPos NOTIFY horizontalPosChanged) public: int horizontalPos() const { return m_horizontalPos; } signals: void horizontalPosChanged();
Then you can open an instance of MyObject for the QML mechanism:
MyObject obj; QQuickView view;
The underline is a nice touch to emphasize the fact that this name comes from the C ++ world.
Finally, in QML, you can simply bind to a property:
Rectangle { x: _myObject.horizontalPos
peppe source share