qml学习----------Flow(流式布局)

Flow布局和Grid布局有点类似,但是Flow没有行列属性, 他会自动根绝宽高来计算item的行列。

import QtQuick 2.2

Rectangle{

    width: 360;
    height: 240;
    color:"#eeeeee";
    id: rootItem;


    Text{
        id: centerText;
        text:"A Signal Text.";
        anchors.horizontalCenter: parent.horizontalCenter;
        anchors.top: parent.top;
        anchors.topMargin: 4;
        font.pixelSize: 24;
        font.bold: true;

    }


    function setTextColor(clr){
        centerText.color = clr;
    }


    Flow{

        anchors.left: parent.left;
        anchors.leftMargin: 4;
        anchors.bottom: parent.bottom;
        anchors.bottomMargin: 4;
        //rows: 3;
        //columns: 3;
        //rowSpacing: 4;
        //columnSpacing: 4;
        width: 280;
        height: 130;
        spacing: 4;

        //描述表格的流模式,如果是LeftToRight 从左到右填充一行,满了就填充第二行
        //flow: Grid.TopToBottom;

        ColorPicker{
            width: 80;
            height: 20;
            color: Qt.rgba(Math.random() , Math.random() , Math.random() , 1.0 );
            onColorPicked: setTextColor(clr);

        }

        ColorPicker{
            width: 100;
            height: 40;
            color: Qt.rgba(Math.random() , Math.random() , Math.random() , 1.0 );
            onColorPicked: setTextColor(clr);

        }

        ColorPicker{
            width: 80;
            height: 25;
            color: Qt.rgba(Math.random() , Math.random() , Math.random() , 1.0 );
            onColorPicked: setTextColor(clr);

        }


        ColorPicker{


            color: Qt.rgba(Math.random() , Math.random() , Math.random() , 1.0 );
            onColorPicked: setTextColor(clr);

        }

        ColorPicker{
            width: 35;
            height: 35;
            color: Qt.rgba(Math.random() , Math.random() , Math.random() , 1.0 );
            onColorPicked: setTextColor(clr);

        }

        ColorPicker{
            width: 20 ;
            height: 80;
            color: Qt.rgba(Math.random() , Math.random() , Math.random() , 1.0 );
            onColorPicked: setTextColor(clr);

        }

        ColorPicker{
            color: Qt.rgba(Math.random() , Math.random() , Math.random() , 1.0 );
            onColorPicked: setTextColor(clr);

        }




    }

}

在没有设置他的flow属性的时候,他的默认属性是lefttoright , 运行效果如下:

在设置flow: Grid.TopToRight 的时候运行效果如下:

可以看出他的差别还是相当的大的,为啥会这样的呢?就是因为他会自动适应item的宽高,比如在LeftToRight模式下,当插入第四个元素的时候,他的宽就大于了Flow的宽度了,所以会被放到下一行来显示。
这个就跟英文单词的显示很类似,当第一行写不下某个单词的时候,一般情况下会放到下一行来进行处理。
而竖直的时候,不会去考虑他的宽度,而是去考虑他的高度是一个道理的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苦茶子12138

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值