gpt4 book ai didi

c++ - 为什么不调用继承自 QSortFilterProxyModel 的 filterAcceptsRow?

转载 作者:可可西里 更新时间:2023-11-01 10:44:21 24 4
gpt4 key购买 nike

有一个名为 customSortFilterProxyModel 的类继承自 QSortFilterProxyModel。一个 protected 函数 filterAcceptsRow 被覆盖。但是,根本不会调用 filterAcceptsRow。问题是什么?谢谢。customSortFilterProxyModel.h

class customSortFilterProxyModel: public QSortFilterProxyModel
{
Q_OBJECT

public:
customSortFilterProxyModel(QObject *parent);
~customSortFilterProxyModel();

protected:
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
};

//customSortFilterProxyModel.cpp
customSortFilterProxyModel::customSortFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
customSortFilterProxyModel::~customSortFilterProxyModel()
{

}
bool customSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
return true;
}

使用这个代理模型测试代码

    QStringListModel *newModel = new QStringListModel;
QStringList strList;
strList << "1" << "2" << "3" << "4";
newModel->setStringList(strList);
customSortFilterProxyModel *m_customSortFilterProxyModel = new customSortFilterProxyModel(this);
m_customSortFilterProxyModel->setSourceModel(newModel);

最佳答案

为排序列调用此函数

m_customSortFilterProxyModel->排序(0);

关于c++ - 为什么不调用继承自 QSortFilterProxyModel 的 filterAcceptsRow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33210507/

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