Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Using values set in QML properties as delegates that are used by C++ QtQuick object



  • I am writing a QtQuick based C++ object. I was wondering if there is a way to use an object set as a property of that object:

    Object {
      delegateObject: Item{}
    }
    

    Where delegateObject is set to a QML object that can be used as a delegate in the QtQuick C++ object. I am creating a C++ object so I can draw some things fast using QSGNodes, but would like to draw other things using QML objects. I assume I would need to somehow read the nodes from the delegate and then generate them at render time. Not sure how this would affect events.


  • Moderators

    @fcarney said in Using values set in QML properties as delegates that are used by C++ QtQuick object:

    delegateObject

    Declare delegateObject as a pointer to QQuickItem. That part should work. However, I have no idea if/ how to the other step (pain the delegate on demand).


  • Qt Champions 2018

    If you only need an instance of an object, use a QQuickItem* property. That's what Controls do for their background property
    If you need to create multiple instances use a QQmlComponent* property. That what views do (like ListView) for their delegate property.


Log in to reply