zoukankan      html  css  js  c++  java
  • QML::Rectangle组件

    QML的Rectangle组件,描绘一个矩形,一个可视化的对象。

    外加设置属性来达到我们想要的效果。常用的有矩形的颜色,边框颜色,圆角等设置。

     Rectangle{
               x:10//这里的坐标是相对于它的父窗口,也就是Window
               y:10
                100;
               height: 100;//一定要指定出大小才能显示
               visible: true
               antialiasing: true;//抗锯齿,默认就是开启的
               border. 10;
               border.color: "red";//边框的一些属性
               color: "blue"//内部的颜色
               radius: 5//圆角半径
               gradient: Gradient{//颜色渐变
                   GradientStop { position: 0.0; color: "lightsteelblue" }
                   GradientStop { position: 1.0; color: "blue" }
               }
               clip:true//这一属性设置表示如果他的子类超出了范围,那么就剪切掉,不让他显示和起作用
               Rectangle{
                   id:son
                   x:50;  //基于父窗口的位置
                   y:50;
                    300;
                   height: 100;
                   color: "gray";
               }
        }

     Rectangle {
            color: "blue"
             100; height: 100
            Rectangle {
                color: "green"
                 25; height: 25
            }
            Rectangle {
                color: "red"
                x: 25; y: 25;  25; height: 25
                scale: 1.5  //放大1.5倍
                transformOrigin: "TopLeft" //改变元素的原点位置
            }
        }

      Row {
              Rectangle {
                   100; height: 100
                  color: "blue"
                  transform: Translate { y: 40 }//下移
              }
              Rectangle {
                   100; height: 100
                  color: "red"
                  transform: Translate { y: -40 }//上移
              }
          }
       Rectangle {
             100; height: 100
            color: "red"
            PropertyAnimation on x { to: 50; duration: 1000; loops: Animation.Infinite } //从(0,0)坐标移动到(50。50),
            PropertyAnimation on y { to: 50; duration: 1000; loops: Animation.Infinite }//1000表示一秒时间, duration 越大移动越慢
        }
        
        Rectangle {
             100; height: 100
            color: "red"
            PropertyAnimation on x { to: 50; duration: 1000; easing.type: Easing.OutBounce }
            PropertyAnimation on y { to: 50; duration: 1000; easing.type: Easing.OutBounce }//移动到50,50 ,OutBounce 动画效果
        }
        
        Rectangle {
             100; height: 100; anchors.centerIn: parent
            color: "red"
            RotationAnimation on rotation { to: 90; direction: RotationAnimation.Clockwise } //旋转90°
        }
        
        Rectangle {
            100; height: 100
           ColorAnimation on color { from: "red"; to: "yellow"; duration: 1000 } //在1s时间内 颜色变化
       }
      // Rectangle 跟随鼠标移动 写法一
        Item {
             100; height: 100
    
            Rectangle {
                id: rect
                 100; height: 100
                color: "red"
    
                Behavior on x { PropertyAnimation { duration: 500 } }
                Behavior on y { PropertyAnimation { duration: 500 } }
            }
    
            MouseArea {
                anchors.fill: parent
                onClicked: { rect.x = mouse.x; rect.y = mouse.y }
            }
        }
    
        // Rectangle 跟随鼠标移动 写法二
        Rectangle {
               id: rect
                100; height: 100
               color: "red"
    
               PropertyAnimation {
                   id: animation
                   target: rect
                   properties: "x,y"
                   duration: 1000
               }
    
               MouseArea {
                   anchors.fill: parent
                   onClicked: {
                       animation.to = 50;
                       animation.running = true;
                   }
               }
           }
        // Rectangle 跟随鼠标移动 写法三
        Rectangle {
               id: rect
                100; height: 100
               color: "red"
    
               MouseArea {
                   anchors.fill: parent
                   onClicked: rect.state = "moved"
               }
    
               states: State {
                   name: "moved"
                   PropertyChanges { target: rect; x: 50; y: 50 }
               }
    
               transitions: Transition {
                   PropertyAnimation { properties: "x,y"; duration: 1000 }
               }
           }
     // 自由落体动画效果
        Rectangle {
            id: rect
             120; height: 200
    
            Image {
                id: img
                source: "colors.png"
                anchors.horizontalCenter: parent.horizontalCenter
                y: 0
    
                SequentialAnimation on y {
                    loops: Animation.Infinite
                    NumberAnimation { to: rect.height - img.height;
                        easing.type: Easing.OutBounce; duration: 2000 }
                    PauseAnimation { duration: 1000 }
                    NumberAnimation { to: 0; easing.type: Easing.OutQuad;
                        duration: 1000 }
                }
            }
        }
  • 相关阅读:
    jQuery---val方法
    jQuery---内容复习
    jQuery---弹幕效果
    执行插件超过2分钟超时错误,如何办?
    Dynamics 365设置错误通知首选项的方法
    Dynamics 365创建用户提示:您正在尝试使用已由其他用户使用的域登录来创建用户。的解决办法
    导入解决方案错误及其解决办法
    Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM 2016 Performance and Scalability Documentation
    Dynamics 365测试和启用邮箱时候一直显示“安排电子邮件配置测试”怎么办?
    控制台程序读取Excel设置角色权限
  • 原文地址:https://www.cnblogs.com/osbreak/p/12067814.html
Copyright © 2011-2022 走看看