If I am rotating a rectangle with different height and width, how do I make it so that the window it is in conforms to those dimensions?
I have a root rectangle (the window itself) which contains some other rectangles in QML and I want it to be rotatable from portrait to landscape but currently when rotating to landscape the window stays the same size while the image and contents of the window rotate and part of what was visible in portrait mode is lost beyond the borders of the window because the window does not resize to reflect the rotation.
In the Example code, the green rectangle lostone
is lost beyond the border of the window and the user has to manually resize the window or rotate back to vertical if they want to see the green rectangle again. I want the window to resize with the background
rectangle
Example:
import QtQuick 2.0
Rectangle {
id: screen
width: 400
height: 500
state: "vertical"
rotation: 0
Rectangle {
id: background
width: 400
height: 500
anchors.centerIn: parent
color: "blue"
Rectangle {
id: lostone
width: 50
height: 50
color: "green"
anchors.top: parent.top
}
Rectangle {
id: rotater
anchors.centerIn: parent
width: 150
height: 50
color: "red"
anchors.horizontalCenterOffset: 0
smooth: true
anchors.horizontalCenter: parent.horizontalCenter
MouseArea {
anchors.fill: parent
onClicked: screen.toggle()
}
}
}
Behavior on width {
NumberAnimation { duration: 100 }
}
Behavior on height {
NumberAnimation { duration: 100 }
}
Behavior on rotation {
NumberAnimation { duration: 100 }
}
function toggle() {
console.log("toggle called, screen state is " + screen.state)
if (screen.state=="vertical") {screen.state = "rotated"; } else { screen.state ="vertical"}
}
states: [
State {
name: "rotated"
PropertyChanges {
target: screen; rotation: -90; width: 400; height: 500
}
},
State {
name: "vertical"
PropertyChanges {
target: screen; rotation: 0; width: 400; height: 500
}
}
]
}