qml rectangle
时间: 2023-08-19 18:06:52 浏览: 116
QML中的Rectangle用于绘制带可选边框的可填充的矩形。你可以使用一些属性来自定义Rectangle的外观,如颜色、边框和圆角效果。在QML代码中,你可以通过导入QtQuick库和创建一个Window来使用Rectangle组件。下面是一个简单的例子:
import QtQuick 2.15
import QtQuick.Window 2.15
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Rectangle {
width: 100
height: 100
anchors.centerIn: parent
color: "lightsteelblue"
radius: 10
border.width: 1
border.color: "blue"
}
}
这个例子中,我们在Window组件中创建了一个Rectangle组件。它的宽度和高度都是100,通过anchors.centerIn属性将它居中显示在父组件中。颜色属性color可以使用字符串、Qt.rgba()函数或十六进制值来定义。radius属性用于设置圆角效果的半径。border.width和border.color属性分别用于设置边框的宽度和颜色。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [QML之Rectangle组件](https://blog.csdn.net/Y03977211367Y/article/details/122384993)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *3* [【Qt QML入门】Rectangle](https://blog.csdn.net/wangyi463295828/article/details/131643823)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文