0

私のQtプロジェクトでは、SQL、テーブルビュー、およびqsortproxymodelを使用して列をフィルタリングしています.問題は、1つの列しかフィルタリングできないことにあります.たとえば、カテゴリ「CATS」とカテゴリ「DOGS」からは、犬と猫の両方のアイテムを表示したい。どうすればそれができますか?

私のソースコードは次のとおりです。

void Animals::on_comboBox_currentTextChanged(... QString &arg1) // class 
{ 
    ProxyModel->setFilterKeyColumn(3); 
    ProxyModel->setFilterFixedString(ui->combobox->currentText());
} 

void Animals::on_comboBox_2_currentTextChange... QString &arg1) // class with letters 
{ 
    ProxyModel->setFilterKeyColumn(4);
    ProxyModel->setFilterFixedString(ui->combobox_2->currentText());
} 

前もって感謝します

4

1 に答える 1

4

QSortFilterProxyModel をサブクラス化し
、ドキュメントの filterAcceptsRow の例を再実装する必要があります。

bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
         const QModelIndex &sourceParent) const
 {
     QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
     QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
     QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);

     return (sourceModel()->data(index0).toString().contains(filterRegExp())
             || sourceModel()->data(index1).toString().contains(filterRegExp()))
            && dateInRange(sourceModel()->data(index2).toDate());
 }
于 2013-08-22T11:31:30.397 に答える