1.在Label上添加矩形区域
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.0
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Label{
id:label_result
anchors.top:parent.top
anchors.topMargin: 30
font.family: "黑体"
font.pixelSize: 14
font.bold: true
color: "white"
background: Rectangle{
radius: 2
anchors.fill: parent
anchors.margins: -5
color: "#FFC95E"
}
anchors.horizontalCenter: parent.horizontalCenter
text: "带背景的Label"
}
}