当前位置: 首页> 房产> 家装 > 陕西疫情最新情况今天_现在进入深圳需要什么条件_百度广告代理公司_web前端培训费用大概多少

陕西疫情最新情况今天_现在进入深圳需要什么条件_百度广告代理公司_web前端培训费用大概多少

时间:2025/8/15 8:42:11来源:https://blog.csdn.net/m0_74224591/article/details/145285012 浏览次数:0次
陕西疫情最新情况今天_现在进入深圳需要什么条件_百度广告代理公司_web前端培训费用大概多少

1.定义TreeModel类

我们需要继承自QAbstractItemModel,让我们来看看它有哪些接口。

QAbstractItemModel类中定义如下:

Q_INVOKABLE virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const = 0;Q_INVOKABLE virtual QModelIndex parent(const QModelIndex &child) const = 0;Q_INVOKABLE virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const;Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0;Q_INVOKABLE virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0;Q_INVOKABLE virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const;Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0;Q_INVOKABLE virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);Q_INVOKABLE virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

其中共5个纯虚函数,index()、parent()、rowCount()、columnCount()和data(),这是我们必须要实现的;另外一般我们还是需要显示表头的,所以还需要实现headerData()。QTreeView显示树时,会自动调用TreeModel,来获取显示一个树所需要的一些信息;我们重写这些函数的目的就是为了向QTreeView提供这些信息的。

接下解释下重写各个函数的作用。

  • QVariant headerData(int section, Qt::Orientation orientation, int role) const override;

  • int section:表示表头的索引。对于水平表头(列标题),它是列的索引;对于垂直表头(行标题),它是行的索引。

  • Qt::Orientation orientation:指定表头的方向,可以是 Qt::Horizontal(水平,即列标题)或 Qt::Vertical(垂直,即行标题)。

  • int role:指定所需数据的类型。在视图模型中,role 用于区分不同类型的数据请求,例如显示数据、工具提示等。

QStringList _headers;
_headers {
        "计划编号",
        "点位序号",
        "高度",
        "调整值",
        "标识"
    };

QVariant TreeModel::headerData(int section, Qt::Orientation orientation,int role) const
{
    if (orientation == Qt::Horizontal)
    {
        if(role == Qt::DisplayRole)
        {
            return _headers[section];
        }
    }
    return QVariant();
}

关键字:陕西疫情最新情况今天_现在进入深圳需要什么条件_百度广告代理公司_web前端培训费用大概多少

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: