gpt4 book ai didi

QT - 将自己的列添加到 QFileSystemModel

转载 作者:行者123 更新时间:2023-12-02 05:13:47 24 4
gpt4 key购买 nike

我可以扩展 QFileSystemModel 并添加带有文本/图标的新列吗?

问候

最佳答案

我将从子类化模型开始,提供额外的列并向其提供数据。

所以至少我会在这两种情况下重新实现 columnCount() 和 data() 调用基类并相应地操作结果。

class yourSystemModel : public QFileSystemModel
{
Q_OBJECT

int columnCount(const QModelIndex& parent = QModelIndex()) const
{
return QFileSystemModel::columnCount()+1;
}

QVariant data(const QModelIndex& index,int role) const
{
if(!index.isValid()){return QFileSystemModel::data(index,role);}
if(index.column()==columnCount()-1)
{
switch(role)
{
case(Qt::DisplayRole):
{return QString("YourText");}
case(Qt::TextAlignmentRole):
{return Qt::AlignHCenter}
default:{}
}
}
return QFileSystemModel::data(index,role);
}
}

官方文档概述了抽象项目模型的最小重新实现的一些基础,但在这种情况下,您可以少得多。 http://doc.qt.digia.com/stable/qabstractitemmodel.html - 子类部分。

关于QT - 将自己的列添加到 QFileSystemModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14962902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com