Qt Quick HelloWorld以及基本QML解析

来源:互联网 发布:edg淘宝店 编辑:程序博客网 时间:2024/06/14 16:51

由于个人需要,本人决定开始 学习Qt Quick。

main.cpp

#include <QGuiApplication>#include <QQmlApplicationEngine>int main(int argc, char *argv[]){    QGuiApplication app(argc, argv);    QQmlApplicationEngine engine;    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));    return app.exec();}
main.qml

import QtQuick 2.2 /**导入了2.2版本的QtQuick模块 部分基本的QML类型如Text,Rectangle,Item,Row等,都在此模块中**/import QtQuick.Window 2.1/**导入2.1版本的Window模块,也就是QML应用顶部的窗口,对应C++类型为QQuickWindow**/Window{    visible:true;    visibility: Window.Maximized; /****最大化 *****/    Rectangle{        width:100;        height:100;        visible:true;        z:1;     //这里相当于 z-index        opacity:0.5;  //透明度        anchors.centerIn: parent  ;//在父窗口里面居中显示        color:"#FF0000";  //背景色(透明可以是transparent)        border.color: "#0000FF" ; //边框颜色        radius: 14; //圆角    }    Rectangle{        id:rect1;        width:500;        height:500;        rotation:90; /****让Rectangle顺时针旋转90度***/        clip:true;//自动裁剪它自己的孩子        gradient:Gradient{            GradientStop{position:0.0;color:"#FF0000";}            GradientStop{position:0.5;color:"#00FF00";}            GradientStop{position:1.0;color:"#0000FF";}            /****position在0.0到1.0之间            color是16进制颜色代码 可以指定任意个GradientStop Qt            会自己进行无缝填充 渐变            ***/        }        anchors.top:parent.top; //先要对齐锚线        anchors.topMargin: 200;//对齐锚线 设置外边距就有用了    }    Rectangle{        id:rect2;        width:50;        height:50;        rotation:90; /****让Rectangle顺时针旋转90度***/        clip:true;//自动裁剪它自己的孩子        color:"#00FF00";        anchors.left:rect1.right; //先要对齐锚线        anchors.leftMargin: 200;//对齐锚线 设置外边距就有用了        anchors.top:parent.top;        anchors.topMargin:200;    }}



0 0