2013-08-22 3 views
0

내 Qt 프로젝트에서 나는 columns를 필터링하기 위해 sql, table view 및 qsortproxymodel을 사용하고 있습니다. 문제는 그 중 하나의 컬럼 만 필터링 할 수 있다는 것입니다. 예를 들어, 카테고리 "CATS"및 카테고리 "DOGS"에서 카테고리 중 하나만 항목을 필터링 할 수 있습니다. 개와 고양이의 두 항목 모두를보고 싶습니다. 어떻게 할 수 있습니까?Qt 어떻게 하나 이상의 열을 필터링 할 수 있습니까?

내 소스 코드는 다음과 같습니다 사전에

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()); 
} 

감사

당신은 QSortFilterProxyModel를 서브 클래스 화해 filterAcceptsRow
문서에서 예를 다시 구현해야
+1

나는 그것을 할 수 없습니다 생각을 QSortFilterProxyModel을 서브 클래 싱하지 않고 –

답변

3

:

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()); 
} 
관련 문제