model中的layoutChanged ()信号 通知视图更新界面

本文介绍如何使用QAbstractItemModel的layoutChanged信号来更新视图布局,特别是在用户交互更改模型数据后。通过实例展示了如何在用户编辑项时触发界面刷新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

void QAbstractItemModel::layoutChanged () [signal]

This signal is emitted whenever the layout of items exposed by the model has changed;

for example, when the model has been sorted(重新排序了). When this signal is received by a view, it should update the layout of items to reflect this change.




例如:当用户勾选了第一列的CheckBox后,要设置model中,QList中存储的值,

然后,通知视图,进行刷新界面


        //允许用户编辑item,必须重写setData()函数
        bool TradeTableModel::setData ( const QModelIndex & index, const QVariant & value, int role/* = Qt::EditRole */)
        {
            //允许用户编辑的只有3列 第一列CheckBox, 包裹数, 保价金额


            if(role == Qt::CheckStateRole && index.column() == ORDER_ID)

            {
                //用户勾选 每行第一列的CheckBox
                ORDER_LIST_STRUCT& orderData = m_OrderList[row];
                orderData.m_bChecked = !orderData.m_bChecked;//修改model中的值,

                //该行checkBox 勾选状态
                emit ModelCheckBoxStateChanged(orderData.m_bChecked ? Qt::Checked : Qt::Unchecked);
                
                emit layoutChanged();
            }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值