qml 简单变换

有3个圣诞树:

点击第1个圣诞树,每点击一次,向右平移10px;

点击第2个圣诞树,每点击一次,旋转角度增加20度;

点击第3个圣诞树,每点击一次,旋转角度增加20度,同时放大0.1。

最后,点击空白处还原所有圣诞树。

 

02.qml

import QtQuick

// x、y - 平移:通过改变x、y的位置完成简单的平移
// rotation - 旋转:值以角度表示(0 ~ 360)
// scale - 缩放:大于1表示放大,小于1表示缩小

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("简单变换")

    //还原所有图像的变化
    MouseArea {
        anchors.fill: parent
        onClicked: {
            p1.x = 0
            p2.rotation = 0
            
            p3.rotation = 0
            p3.scale = 0.5
        }
    }

    ClickedChangeImage {
        id: p1
        source: "images/Christmas tree.png"
        scale: 0.5
        x: 0
        y: 0
        onClicked: {
            x += 10
        }
    }

    ClickedChangeImage {
        id: p2
        source: "images/Christmas tree.png"
        scale: 0.5
        x: 150
        y: 0

        onClicked: {
            rotation += 20
        }
    }

    ClickedChangeImage {
        id: p3
        source: "images/Christmas tree.png"
        scale: 0.5
        x: 300
        y: 0

        onClicked: {
            rotation += 20 //旋转角度增加20度
            scale += 0.1 //比例放大10%
        }
    }
}

ClickedChangeImage.qml

import QtQuick

Image {
    id: root
    signal clicked

    MouseArea {
        anchors.fill: parent
        onClicked: {
            root.clicked()
        }
    }
}

相关推荐

  1. Qt/QML编程之路:qml通过C++传递变量给另一个qml(42)

    2024-01-23 08:42:01       58 阅读
  2. 认识QML

    2024-01-23 08:42:01       29 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-23 08:42:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-23 08:42:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-23 08:42:01       87 阅读
  4. Python语言-面向对象

    2024-01-23 08:42:01       96 阅读

热门阅读

  1. gin框架复习

    2024-01-23 08:42:01       55 阅读
  2. Elasticsearch 查询超过10000 的解决方案 - Python

    2024-01-23 08:42:01       63 阅读
  3. vue v-for 为什么要加 key

    2024-01-23 08:42:01       44 阅读
  4. mac os电脑用n切换node版本

    2024-01-23 08:42:01       46 阅读
  5. 如何进行技术选型

    2024-01-23 08:42:01       50 阅读
  6. 网络安全小白进阶试题——附答案

    2024-01-23 08:42:01       52 阅读
  7. flask web 学习之用户认证与会话管理

    2024-01-23 08:42:01       56 阅读