Qml:锚点

简介: Qml:锚点
import QtQuick
import QtQuick.Window
Window {
    width: 800
    height: 600
    visible: true
    title: qsTr("Test Anchors")
    ///锚点 上下左右
    Rectangle
    {
        id: anchor1
        width:200
        height: 150
        color:"#EEEEEE"
        Rectangle
        {
            id:rect1
            width:50
            height:50
            color: "red"
            Text{text:"rect1"}
        }
        Rectangle
        {
            id:rect2
            width:50
            height:50
            color: "blue"
            Text{text:"rect2"}
            anchors.left: rect1.right
        }
        Rectangle
        {
            id:rect3
            width:50
            height:50
            color: "green"
            Text{text:"rect3"}
            anchors.top: rect1.bottom
        }
        Rectangle
        {
            id:rect4
            width:50
            height:50
            color: "pink"
            Text{text:"rect4"}
            anchors.left: rect3.right
            anchors.top: rect2.bottom
        }
    }
    ///锚点 动态大小
    Rectangle
    {
        id: anchor2
        anchors.left:anchor1.right
        anchors.leftMargin: 5 //左侧间距
        width:200
        height: 150
        color:"#EEEEEE"
        Rectangle
        {
            id:leftpage
            width: 50
            color:"blue"
            anchors.top: parent.top         //自动拉升高度
            anchors.bottom: parent.bottom
            Text{text:"left"}
        }
        Rectangle
        {
            id:mainpage
            color:"pink"
            anchors.top: parent.top         //自动拉升高度
            anchors.bottom: parent.bottom
            anchors.left:leftpage.right     //自动拉升宽度
            anchors.right: rightpage.left
            Text{text:"main"}
        }
        Rectangle
        {
            id:rightpage
            width: 50
            color:"green"
            anchors.top: parent.top         //自动拉升高度
            anchors.bottom: parent.bottom
            anchors.right: parent.right
            Text{text:"right"}
        }
        MouseArea
        {
            anchors.fill: parent
            onClicked:
            {
                parent.width +=10
                parent.height +=10
            }
        }
    }
    Rectangle
    {
        id:anchor3
        //通过anchor2、和窗口 锚定宽高和位置
        anchors.left: anchor2.right
        anchors.right: parent.right
        anchors.top: anchor2.top
        anchors.bottom: anchor2.bottom
        anchors.leftMargin: 5
        color:"#EEEEEE"
        //水平居中
        Rectangle
        {
            id:hcenter
            color:"red"
            width:50
            //拉升高度
            anchors.top: parent.top
            anchors.bottom: parent.bottom
            //水平居中
            anchors.horizontalCenter: parent.horizontalCenter
        }
        Rectangle
        {
            width:50
            height: 50
            color:"blue"
            //垂直居中
            anchors.verticalCenter:hcenter.verticalCenter
            anchors.left: hcenter.right
        }
        //完全居中
        Rectangle
        {
            width:50
            height: 50
            color:"yellow"
            anchors.centerIn: parent
        }
    }
}


相关文章
|
2月前
|
C#
浅谈WPF之装饰器实现控件锚点
使用过visio的都知道,在绘制流程图时,当选择或鼠标移动到控件时,都会在控件的四周出现锚点,以便于修改大小,移动位置,或连接线等,那此功能是如何实现的呢?在WPF开发中,想要在控件四周实现锚点,可以通过装饰器来实现,今天通过一个简单的小例子,简述如何在WPF开发中,应用装饰器,仅供学习分享使用,如有不足之处,还请指正。
90 1
|
2月前
QML (控件位置布局)之(Anchors)锚布局
QML (控件位置布局)之(Anchors)锚布局
113 2
|
2月前
|
算法 程序员 人机交互
【QML 设置颜色】QML中的色彩魔法:从取色器到用户界面
【QML 设置颜色】QML中的色彩魔法:从取色器到用户界面
175 0
|
9月前
|
存储 UED
Qt自定义控件之动画文本
Qt自定义控件之动画文本
|
11月前
|
前端开发 定位技术
QT使用QML实现地图绘制虚线
QML提供了MapPolyline用于在地图上绘制线段,该线段是实线,因此我使用Canvas自定义绘制的方式在地图上绘制线段
163 0
|
Windows
C#-利用自定义控件绘制一个箭头控件
利用自定义控件绘制一个箭头控件
602 0
|
JSON 前端开发 JavaScript
Threejs引入字体,实现3D文字,Canvas画布作为纹理贴图实现滚动字幕
Threejs引入字体,实现3D文字,Canvas画布作为纹理贴图实现滚动字幕
788 0
Threejs引入字体,实现3D文字,Canvas画布作为纹理贴图实现滚动字幕
|
存储 Swift
SwiftUI极简教程38:ScrollViewReader滚动视图锚点的使用
在本章中,你将学会ScrollViewReader滚动视图锚点的使用。
757 0
SwiftUI极简教程38:ScrollViewReader滚动视图锚点的使用
|
C++
duilib corner属性的贴图技巧——让图片自动贴到控件的的某一边或者一角并自适应控件的大小
转载请说明原出处,谢谢~~          Duilib给控件贴图功能可以附带多个属性,各个属性的配合可以达到许多效果。以下是duilib支持的所有贴图属性: 贴图描述:          Duilib的表现力丰富很大程度上得益于贴图描述的简单强大。
1744 0