zhuzichu520 / FluentUI

FluentUI for QML
MIT License
3.16k stars 422 forks source link

FluTableView 无法动态修改列名 #386

Open jeffrey0326 opened 6 months ago

jeffrey0326 commented 6 months ago

FluTableView{ id:table_view anchors{ left: parent.left right: parent.right top: parent.top bottom: gagination.top } anchors.topMargin: 20 columnSource:[ { title: '姓名', dataIndex: 'name', readOnly:true, }, { title: '住址', dataIndex: 'address', width:200, minimumWidth:100, maximumWidth:250 } ] }

FluFilledButton{
    text:"更改列"
    anchors{
        left:parent.left
        bottom:parent.bottom
    }
    onClicked:{
        changeColumn()
    }
}

function changeColumn(){
    if(changecolumn==0){
        changecolumn=1
        table_view.columnSource =  [
                    {
                        title: table_view.customItem(com_column_checbox,{checked:true}),
                        dataIndex: 'checkbox',
                        width:80,
                        minimumWidth:80,
                        maximumWidth:80,
                    },
                    {
                        title: '头像',
                        dataIndex: 'avatar',
                        width:100,
                        minimumWidth:100,
                        maximumWidth:100
                    },
                    {
                        title: '姓名',
                        dataIndex: 'name',
                        readOnly:true,
                    }
                ]
    }else{
        changecolumn=0
        table_view.columnSource =  [
                    {
                        title: '长字符串',
                        dataIndex: 'longstring',
                        width:200,
                        minimumWidth:100,
                        maximumWidth:300
                    },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        width:160,
                        minimumWidth:160,
                        maximumWidth:160
                    }
                ]
    }
}

` 在example中,尝试修改columnSource ,程序会崩溃闪退,Qt时5.15.2 + MSVC 2019

suterberg commented 6 months ago

这个不是这样改的吧,用states试试

jeffrey0326 commented 6 months ago

这个不是这样改的吧,用states试试

增删改数据列也不是用states吧?

suterberg commented 6 months ago

你是只切换表头还是表头数据一起换,一起换用两个model不就行了各管各的


---- 回复的原邮件 ----
发件人 ***@***.***>
日期 2023年12月30日 23:49
收件人 ***@***.***>
抄送至 ***@***.***>***@***.***>
主题 Re: [zhuzichu520/FluentUI] FluTableView 无法动态修改列名 (Issue #386)

这个不是这样改的吧,用states试试

增删改数据列也不是用states吧?


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: <zhuzichu520/FluentUI/issues/386/1872552379@github.com>

zhuzichu520 commented 6 months ago

example已添加修改列名示例https://github.com/zhuzichu520/FluentUI/commit/475d29390663a4282a7ba293f5c54698e8f40978 1703992834337

jeffrey0326 commented 6 months ago

感谢大佬回复,又学到了!不过我的希望是,更改显示的数据列,必须数据dataSource中又a、b、c、d四列,如果我columnSource定义了a、b、c列的dataIndex和title,table就会只显示这三列,希望控制修改columnSource的dataIndex和title,来调整显示的列a、b、c、d列的数据,确实只能修改整个model吗?

suterberg commented 6 months ago

这个不是这样改的吧,用states试试

增删改数据列也不是用states吧?

为什么不用states,你最终的数据是在c++里边吧,用state切换cloumnsource和datasource 不是更明确么,用qml不就是要把界面和模型分开么

jeffrey0326 commented 6 months ago

主要菜鸟还不太会自定义model,看来还是必须得学起来了0.0