• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

qml学习:对象和属性

qml学习:对象和属性


 

本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.


参考文档<<Qt及Qt Quick开发实战精解.pdf>>


 

 

环境:

主机:WIN7

开发环境:Qt


源代码:

 

import QtQuick 1.0

Rectangle
{
    width:320
    height:240
    color:"blue"

    Image
    {
        source:"pics/1.jpg"
        anchors.centerIn: parent
    }

    Text
    {
        id:txt1
        text:"Hello JDH!"
        font.pointSize: 24
        font.bold: true
        anchors.centerIn: parent
    }
 }


运行效果:

 


说明:

代码中有1个对象:Rectangle

2个子对象:Image,Text

每个对象都可以设置属性,以及设置唯一ID


可以通过id访问对象,示例代码:

 

import QtQuick 1.0

Rectangle
{
    width:320
    height:240
    color:"blue"

    Image
    {
        source:"pics/1.jpg"
        anchors.centerIn: parent
    }

    Text
    {
        id:txt1
        text:"Hello JDH!"
        font.pointSize: 24
        font.bold: true
        anchors.centerIn: parent
    }

    Text
    {
        id:txt2
        x: -10
        y: 199
        text:txt1.text + "It is qml!"
        font.pointSize: 24
        font.bold: true
    }
 }


运行效果:

 




posted @ 2013-09-26 22:50  Class Xman  阅读(321)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3