Qt Quick——新建一个QML

1、建一个Qt Quick Application程序,然后修改main.qml文件

  修改Windows中的内容,修改如下:

 1 import QtQuick 2.6
 2 import QtQuick.Window 2.2
 3 
 4 Window {//在VS中 没有Window,有Rectangle。所以不要修改根元素的名字
 5     visible: true
 6     /*声明属性:
 7         <属性名称>:<属性值>
 8     */
 9     x:0;y:0
10     width: 360
11     height: 480
12     title: qsTr("Hello World")
13 
14     Image{
15         source:"file:///F:/Workspace/Qt/QtQuick/image/sunny.png"
16        // source:"../image/sunny.png"
17     }
18     MouseArea{
19         anchors.fill: parent
20         onClicked: {// 鼠标点击事件
21             Qt.quit()
22         }
23     }
24     Text{
25         id:text
26         y:image.height +20
27         property int age: 12
28         /*自定义变量
29             property type name: value
30             property 类型 变量名:变量值
31         */
32         text:"This is Qt Quick   "+12
33     }
34 }

在Image子元素中
  在VS+Qt中:使用相对路径,可以加载jpg图片不能加载png图片
  在Qt Creator中:使用 绝对路径file可以加载png、jpg图片
  资源文件没有试。

猜你喜欢

转载自www.cnblogs.com/wangbin-heng/p/9557395.html