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
        }
    }
}


相关文章
|
9月前
|
C#
浅谈WPF之装饰器实现控件锚点
使用过visio的都知道,在绘制流程图时,当选择或鼠标移动到控件时,都会在控件的四周出现锚点,以便于修改大小,移动位置,或连接线等,那此功能是如何实现的呢?在WPF开发中,想要在控件四周实现锚点,可以通过装饰器来实现,今天通过一个简单的小例子,简述如何在WPF开发中,应用装饰器,仅供学习分享使用,如有不足之处,还请指正。
176 1
|
6月前
QML 界面切换的方法
QML 界面切换的方法
410 1
|
8月前
Qml:鼠标事件
Qml:鼠标事件
|
9月前
QML (控件位置布局)之(Anchors)锚布局
QML (控件位置布局)之(Anchors)锚布局
348 2
|
9月前
|
算法 程序员 人机交互
【QML 设置颜色】QML中的色彩魔法:从取色器到用户界面
【QML 设置颜色】QML中的色彩魔法:从取色器到用户界面
544 0
WPF控件和窗体一起放大一起缩小
WPF控件和窗体一起放大一起缩小
276 0
|
C# Windows
WPF的WindowsFormsHost上浮动控件方法
如何在WPF的WindowsFormsHost实现浮动控件
315 0
|
Windows
C#-利用自定义控件绘制一个箭头控件
利用自定义控件绘制一个箭头控件
755 0
|
存储 Swift
SwiftUI极简教程38:ScrollViewReader滚动视图锚点的使用
在本章中,你将学会ScrollViewReader滚动视图锚点的使用。
859 0
SwiftUI极简教程38:ScrollViewReader滚动视图锚点的使用

热门文章

最新文章