I've an application made by another person and I need to fix it. There's a chart on the view and a textbox for filtering the chart but filter doesnt work. For some reason QRegExp cant find anything.
I am using QT5.12.1 and VS2015.
void ChartWidget::filterSeriesByName(QString name) {
// QString text=ui.lineEditFilterByName->text();
QRegExp regExp(name, Qt::CaseSensitive);
proxyModel->setFilterRegExp(regExp);
setFilterLabel();
foreach (QLegendMarker* marker, chart->legend()->markers())
{
if(regExp.isEmpty() || regExp.exactMatch(marker->series()->name())) {
setMarkerVisible(marker,true,true);
}
else {
setMarkerVisible(marker,true,false);
}
}
}
void ChartWidget::setFilterLabel() {
//resetVerticalHeader();
QString filteredCount = QString::number(proxyModel->rowCount()).append(" / ");
filteredCount.append(QString::number(model->rowCount()));
filteredCount.append(" kayıt gösteriliyor");
ui.labelFilter->setText(filteredCount);
QFont font = ui.labelFilter->font();
if (proxyModel->rowCount() != model->rowCount()) {
ui.labelFilter->setForegroundRole(QPalette::Link);
font.setStyle(QFont::StyleItalic);
ui.labelFilter->setFont(font);
} else {
ui.labelFilter->setForegroundRole(QPalette::WindowText);
font.setStyle(QFont::StyleNormal);
ui.labelFilter->setFont(font);
}
}
I had somewhat similar thingy and it worked when I've added a regex to parameter QString. Try this:
....
QString filterStr = "^.*"+name+".*$";
QRegExp regExp(filterStr);
....