QML自学之路(1)使用自定义控件

自学qml,如有错误请指出
参考资料来源:
资料: QMbook.

CSS:颜色查找.

自定义自己想要的控件,以一个矩形来说明

//RedSquare.qml  文件名字就是控件的名字,首字母要大写
import QtQuick 2.0

Rectangle {
    
    
    width: 50
    height: 50
    color: "#DC143C"
    border.color: Qt.lighter(color)
}

在main.qml里调用

import QtQuick 2.13
import QtQuick.Window 2.13

Window {
    
    
    visible: true
    width: 640
    height: 480
    color: "black"
    title: qsTr("Hello World")
    RedSquare {
    
    

    }
}

目录结构
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43387612/article/details/103533468