qml stacklayout设置颜色
时间: 2023-09-27 13:05:48 浏览: 201
在QML中,可以使用QML属性设置StackLayout的背景色。可以使用background属性来设置StackLayout的背景色。以下是一个例子:
```
import QtQuick 2.0
import QtQuick.Controls 2.0
ApplicationWindow {
id: mainWindow
width: 640
height: 480
visible: true
StackLayout {
id: stackLayout
anchors.fill: parent
Rectangle {
color: "red"
width: stackLayout.width
height: stackLayout.height
Text {
text: "Page 1"
color: "white"
font.pixelSize: 40
anchors.centerIn: parent
}
}
Rectangle {
color: "blue"
width: stackLayout.width
height: stackLayout.height
Text {
text: "Page 2"
color: "white"
font.pixelSize: 40
anchors.centerIn: parent
}
}
}
}
```
在上面的例子中,我们使用Rectangle元素作为StackLayout的子元素。我们设置了两个Rectangle元素,一个是红色的,一个是蓝色的,用于表示StackLayout的两个页面。我们使用color属性来设置Rectangle的颜色。我们还使用Text元素在Rectangle中心显示页面号码。
阅读全文
相关推荐














