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

Surface3D size is just 1x1



  • I'm writing a QML application with C++ singleton back-end.
    My qml defines an Item which contains a Surface3D:

    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Item {
            width: 640
            height: 480
            objectName: "surface3DItem"
    
            Surface3D {
    	    objectName: "surface3D"
                width: parent.width
                height: parent.height
    

    After my C++ is instantiated, my code reads the width and height of Item (named "surface3DItem") and width and height of Surface3D (named "surface3D"):

    object = g_rootWindow->findChild<QObject *>("surface3DItem");
    qDebug() << "surface3DItem width: " << ((QQuickItem *)object)->width();
    qDebug() << "surface3DItem height: " << ((QQuickItem *)object)->height();
    
    object = g_rootWindow->findChild<QObject *>("surface3D");
    qDebug() << "surface3D width: " << ((Surface3D *)(object)->width();
    qDebug() << "surface3D height: " << ((Surface3D *)(object)->height();
    

    Since my qml explicitly specifies Item width=640 and height=480, I would expect the enclosed Surface3D to have the same. But instead my app prints:

    surface3DItem width:  640
    surface3DItem height:  480
    surface3D width:  1
    surface3D height:  1
    

    Why is the Surface3D only 1x1, while its parent Item is 640x480?

    Thanks
    Tom


Log in to reply