【问题标题】:How to replace children in Qt Model-View framework?如何在 Qt Model-View 框架中替换子项?
【发布时间】:2013-09-18 13:17:04
【问题描述】:

我正在使用QAbstractItemModel 来实现我的模型。我有一个父项,想用另一组子项替换它的子项。更换前后,我应该使用哪些模型方法?或者我应该发出什么模型信号?谢谢。

【问题讨论】:

    标签: c++ qt model-view


    【解决方案1】:

    在模型中,parent 是父项的 QModelIndex,count 是要添加的子项的数量:

    beginRemoveRows(parent, 0, rowCount(parent));
    //remove from data
    endRemoveRows();
    beginInsertRows(parent, 0, count);
    //add rows into data
    endInsertRows();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      相关资源
      最近更新 更多