Can anybody give me some idea to create a filter mechanism (as available in Microsoft Excel) on QTableWidget?
Whenever I click on a column name, I want the header filter mechanism to automatically activate for that table.
I'm building on Windows.
UPDATE Here is a partial implementation I have. But I need help with the implemetation of slot testanother(const QString &text)
to display matching data in table and hide unmatched data.
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();
}