I have not found a solution to this problem myself. But examples that illustrate the problem are as following.
A vertical gradient, anchored to parent. All is normal here.
import Qt 4.7
Rectangle {
width: 800
height: 600
id: mainContainer
color: "red"
Rectangle {
anchors.margins: 10
anchors.fill: parent
gradient: Gradient {
GradientStop { position: 0.0; color: "black" }
GradientStop { position: 0.5; color: "white" }
GradientStop { position: 1.0; color: "black" }
}
}
}
import Qt 4.7
Rectangle {
width: 800
height: 600
id: mainContainer
color: "red"
Rectangle {
anchors.margins: 10
anchors.fill: parent
gradient: Gradient {
GradientStop { position: 0.0; color: "black" }
GradientStop { position: 0.5; color: "white" }
GradientStop { position: 1.0; color: "black" }
}
}
}
To copy to clipboard, switch view to plain text mode
But now if you would like to have a horizontal gradient, you would be forced to rotate the rectangle. But the result is not what one would expect:
import Qt 4.7
Rectangle {
width: 800
height: 600
id: mainContainer
color: "red"
Rectangle {
anchors.margins: 10
anchors.fill: parent
rotation: 270
gradient: Gradient {
GradientStop { position: 0.0; color: "black" }
GradientStop { position: 0.5; color: "white" }
GradientStop { position: 1.0; color: "black" }
}
}
}
import Qt 4.7
Rectangle {
width: 800
height: 600
id: mainContainer
color: "red"
Rectangle {
anchors.margins: 10
anchors.fill: parent
rotation: 270
gradient: Gradient {
GradientStop { position: 0.0; color: "black" }
GradientStop { position: 0.5; color: "white" }
GradientStop { position: 1.0; color: "black" }
}
}
}
To copy to clipboard, switch view to plain text mode
I attached snapshots of the painted result of posted example QML.
EDIT: Also there seems to be a bug report of similar nature -> QTBUG-10644
Bookmarks