Qt qml主窗口背景渐变

Qt qml主窗口背景渐变,qt,qml,qmainwindow,Qt,Qml,Qmainwindow,我有这样的想法。 我想在myApp主窗口中使用渐变而不是单色背景 我测试了不同的代码方式,但没有成功 结果总是一样的。背景为纯白色或显示黑白渐变(见图) 你能告诉我怎么做才对吗?我需要颜色深一点的。此外,可能还有其他颜色。但这一切都是黑白的 }您必须将渐变停止列表应用于可视项的渐变属性 要在项中使用矩形,必须指定项的尺寸,默认情况下,项的高度和宽度为零 使用径向梯度 import QtQuick 2.9 import QtQuick.Controls 2.2 import QtGrap

我有这样的想法。 我想在myApp主窗口中使用渐变而不是单色背景

我测试了不同的代码方式,但没有成功

结果总是一样的。背景为纯白色或显示黑白渐变(见图)

你能告诉我怎么做才对吗?我需要颜色深一点的。此外,可能还有其他颜色。但这一切都是黑白的


}

您必须将渐变停止列表应用于可视项的
渐变属性

要在
项中使用矩形
,必须指定项的尺寸,默认情况下,项的高度和宽度为零




使用径向梯度

import QtQuick 2.9
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0

ApplicationWindow {
id: window
visible: true
width: 425
height: 850
title: qsTr("myApp")

Item
{
    anchors.fill: parent
     RadialGradient
    {
        anchors.fill: parent
        gradient: Gradient{
        GradientStop {position: 0.000;color: Qt.rgba(1, 0, 0, 1);}
        GradientStop {position: 0.167;color: Qt.rgba(1, 1, 0, 1);}
        GradientStop {position: 0.333;color: Qt.rgba(0, 1, 0, 1);}
        GradientStop {position: 0.500;color: Qt.rgba(0, 1, 1, 1);}
        GradientStop {position: 0.667;color: Qt.rgba(0, 0, 1, 1);}
        GradientStop {position: 0.833;color: Qt.rgba(1, 0, 1, 1);}
        GradientStop {position: 1.000;color: Qt.rgba(1, 0, 0, 1);}
        }
    }
}
}


您必须将渐变停止列表应用于可视项的
渐变属性

要在
项中使用矩形
,必须指定项的尺寸,默认情况下,项的高度和宽度为零




使用径向梯度

import QtQuick 2.9
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0

ApplicationWindow {
id: window
visible: true
width: 425
height: 850
title: qsTr("myApp")

Item
{
    anchors.fill: parent
     RadialGradient
    {
        anchors.fill: parent
        gradient: Gradient{
        GradientStop {position: 0.000;color: Qt.rgba(1, 0, 0, 1);}
        GradientStop {position: 0.167;color: Qt.rgba(1, 1, 0, 1);}
        GradientStop {position: 0.333;color: Qt.rgba(0, 1, 0, 1);}
        GradientStop {position: 0.500;color: Qt.rgba(0, 1, 1, 1);}
        GradientStop {position: 0.667;color: Qt.rgba(0, 0, 1, 1);}
        GradientStop {position: 0.833;color: Qt.rgba(1, 0, 1, 1);}
        GradientStop {position: 1.000;color: Qt.rgba(1, 0, 0, 1);}
        }
    }
}
}


谢谢。它似乎有用。如何制作径向梯度?我不明白为什么属性可用,但返回错误。当我将
gradient:gradient
更改为
gradient:RadialGradient
时,生成返回错误:
qrc:/main2。qml:128无法将对象分配给属性
谢谢。它似乎有用。如何制作径向梯度?我不明白为什么属性可用,但返回错误。当我将
gradient:gradient
更改为
gradient:RadialGradient
时,生成返回错误:
qrc:/main2。qml:128无法将对象指定给属性
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0

ApplicationWindow {
id: window
visible: true
width: 425
height: 850
title: qsTr("myApp")

Item
{
    anchors.fill: parent
     RadialGradient
    {
        anchors.fill: parent
        gradient: Gradient{
        GradientStop {position: 0.000;color: Qt.rgba(1, 0, 0, 1);}
        GradientStop {position: 0.167;color: Qt.rgba(1, 1, 0, 1);}
        GradientStop {position: 0.333;color: Qt.rgba(0, 1, 0, 1);}
        GradientStop {position: 0.500;color: Qt.rgba(0, 1, 1, 1);}
        GradientStop {position: 0.667;color: Qt.rgba(0, 0, 1, 1);}
        GradientStop {position: 0.833;color: Qt.rgba(1, 0, 1, 1);}
        GradientStop {position: 1.000;color: Qt.rgba(1, 0, 0, 1);}
        }
    }
}
}