ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

20200303-03 QML TableView(Qt5.12) 设置行/列表头

2020-03-03 20:40:18  阅读:962  来源: 互联网

标签:20200303 03 Qt5.12 parent color tableView ScrollBar TableView model


一、前言

  针对最新版本 TableView 如何设置表头,在新版中直接继承 Flickable 所以各项效果更加完备,由于需要频繁弹出和压入数据以保证资源的最大利用,官方建议不太适合静态类型的 delegate

       新版中,使用 index 进行数据索引,不再使用 styleData 关键字

二、示例

    TableView {
        anchors {
            top: parent.top
            bottom: bottomCheckGroup.top
            left: parent.left
            right: parent.right
            topMargin: 0
            leftMargin: 0
            rightMargin: 0
            bottomMargin: 2
        }

        id: tableView
        //QML 新出的设置行宽和列宽的方式,如果需要某一行隐藏,只需要将这一行返回值设置为 0 即可
        //具体看官方文档
        columnWidthProvider: function (column) { return __headWidth; }
        rowHeightProvider: function (column) { return 25; }


        leftMargin: rowsHeader.implicitWidth
        topMargin: columnsHeader.implicitHeight
        model: MyAdjustModel {

            id: table_model
        }


        ScrollBar.horizontal: ScrollBar{}
        ScrollBar.vertical: ScrollBar{}
        clip: true

        //用于关闭拖动效果
        boundsBehavior: Flickable.OvershootBounds
        reuseItems: false
        delegate: SysTableViewDelegate {
        }
        //左上角内容
        SysTableLeftTopMaskDelegate {

        }
        //列头部 利用 Repeater 自动重复生成
        //SysTableTextColumnsHeaderDelegate 是本人自定义变量需要替换
        //新版 TableView 使用 index 进行数据索引        
        Row {
            id: columnsHeader
            y: tableView.contentY
            z: 2

            Repeater {
                model: tableView.columns > 0 ? tableView.columns : 1
                SysTableTextColumnsHeaderDelegate{
                    width: tableView.columnWidthProvider(modelData)
                    height: 65
                    color: __bordColor
                    titleWorkObj: table_model.getTitleParent(index)
                }
            }
        }
        //行头部
        Column {
            id: rowsHeader
            x: tableView.contentX
            z: 2
            Repeater {
                model: tableView.rows > 0 ?  tableView.rows : 1
                Rectangle {
                    width: 60
                    height: tableView.rowHeightProvider(modelData)
                    color: __bordColor
                    Label {
                         anchors.fill: parent
                         anchors {bottomMargin: 2}
                         anchors.centerIn: parent
                         text: table_model.headerData(modelData, Qt.Vertical)
                         color: '#7785a9'
                         font.pixelSize: 15
                         padding: 10
                         verticalAlignment: Text.AlignVCenter
                         horizontalAlignment: Text.AlignHCenter
                         background: Rectangle { color: "white" }
                    }
                }
            }
        }

        ScrollIndicator.horizontal: ScrollIndicator { }
        ScrollIndicator.vertical: ScrollIndicator { }
    }

三、图示

 

标签:20200303,03,Qt5.12,parent,color,tableView,ScrollBar,TableView,model
来源: https://blog.csdn.net/qq_24890953/article/details/104640454

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有