masoume
masoume

Reputation: 33

qml problem to resizeable scene3d in layout

In order to make a resizable 3d program i have created a scene3d in a layout and set the required properties. The scene resizing works properly while i change the height of windows but not in case of changing width. I checked two examples of QTquick 3D and find out there's the same problem there. To solve that i tried resizing windows by dynamic change scene scale in transform matrix4*4, and got this error:

error message

after i ignore this, the program works correctly and resizes scene

AirplaneScene.qml:

Transform {
    id: toyplaneTransform
    matrix: {
        var m = Qt.matrix4x4();
        m.translate(Qt.vector3d(-30, -15, -30));
        m.rotate(angle, Qt.vector3d(0, 1, 0));
        m.rotate(rollAngle, Qt.vector3d(1, 0, 0));
        m.rotate(pitchAngle, Qt.vector3d(0, 0,1));
        m.scale(1.0 /scaleFactor );
        return m;
    }

main.qml:

Item{
     id:sceneItem
     Layout.preferredHeight: 700
     Layout.preferredWidth: 1200
     Layout.fillWidth: true
     Layout.fillHeight: true
     AirplaneScene{
        id:airplane
        scaleFactor: Math.round(mainLayout.width/sceneItem.width * 10) / 10
    }
}

(when manually set the scalafactor this error not displaying)

Upvotes: 1

Views: 153

Answers (1)

masoume
masoume

Reputation: 33

I solved this problem by initialization scalefaktor with 3d scene to mainLayout ratio in AirplaneScene qml, and after loading page i changed scalefaktor dynamically

main.qml

property bool completeLoad: false
Component.onCompleted: {
    completeLoad = true
}
onWidthChanged: {
    if(completeLoad)
        plane.scaleFactor= Math.round(mainLayout.width/sceneItem.width * 10) / 10

}

initialization scalefaktor in AirplaneScene.qml:

property real scaleFactor:1.3

Upvotes: 0

Related Questions