【发布时间】:2012-01-13 03:13:04
【问题描述】:
谁能给我一些想法来在 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();
}
【问题讨论】:
-
你好 Lekhraj。欢迎来到 StackOverflow。 (顺便说一句,尽管填写您的帐户详细信息(例如用户名)会有所帮助,但您无需在帖子上签名。)您是否专门寻找这种机制? microsoft.com/business/smb/en-ca/smallbiz/products/howto/…
-
@HostileFork,是的,我想实现与您共享的链接中提到的相同格式,但我想通过 QT 代码而不是通过 xls 来实现。
标签: excel qt datagrid filter qtablewidget