QTableWidget で (Microsoft Excel で利用可能な) フィルター メカニズムを作成するアイデアを誰か教えてもらえますか?
列名をクリックするたびに、ヘッダー フィルター メカニズムがそのテーブルに対して自動的にアクティブになるようにします。
私はWindows上で構築しています。
更新これは私が持っている部分的な実装です。testanother(const QString &text)
しかし、一致するデータをテーブルに表示し、一致しないデータを非表示にするスロットの実装について助けが必要です。
bool TableData::filterSlot() {
int columnCount = this->tablewidget->columnCount();
int rowCount = this->tablewidget->rowCount();
QStringList filterList;
QString temp_string;
qDebug()<<"Count inside filter slot is";
qDebug()<<rowCount<<":"<<columnCount;
for(int c = 0; c<columnCount;c++) {
for(int r = 0; r<rowCount;r++) {
temp_string = this->tablewidget->item(r,c)->text();
if(!filterList.contains(temp_string))
filterList << temp_string;
}
filterList << "None";
combo = new QComboBox(tablewidget);
combo->addItems(filterList);
combo->setCurrentIndex(filterList.count()-1);
this->tablewidget->setCellWidget(0,c,combo);
filterList.clear();
connect(combo,SIGNAL(activated(const QString &)),
this,SLOT(testAnother(const QString &)));
}
return true;
}
void TableData::testAnother(const QString &text) {
int c = sender()->objectName().toInt();
}