PDA

View Full Version : QRegExp not (!) can you filter based on QRegExp not be matched?



jfinn88
7th March 2017, 00:18
m_UserModelProxy = new UserModelProxy(this);
m_UserModelProxy->setSourceModel(this);
m_UserModelProxy->setDynamicSortFilter(true);
m_UserModelProxy->setSortCaseSensitivity(Qt::CaseInsensitive);

m_UserModelProxy->setFilterRole(UsersModel::IDRole);
QRegExp filter("ametinc");
m_UserModelProxy->setFilterRegExp(filter); //I want to filter out ametinc from the model but it filters everything else is there a way to QRegExp is not equal to ametinc ....


this may not be the correct way to achieve this however I figured if I could filter out the one item form the model I don’t want to display I figured I try proxyModel


I'm still having a little trouble filtering out the ametinc user, I can set a proxy filter to filter out everything else besides ametinc cause thats what the filter is set to, I'm not sure how to get it to remove or hide it form the model though here is some code I been thinking about

the RegExp its filtering what to display I want to filter what not to display if that makes sense



m_UserModelProxy = new UserModelProxy(this);
m_UserModelProxy->setSourceModel(this);
m_UserModelProxy->setDynamicSortFilter(true);
m_UserModelProxy->setSortCaseSensitivity(Qt::CaseInsensitive);

m_UserModelProxy->setFilterRole(UsersModel::IDRole);
QRegularExpression filter("ametinc");
if(filter.hasMatch()){
removeUser(filter.index);
}
m_UserModelProxy->setFilterRegExp(filter);

//m_UserModelProxy->setFilterRegExp(QRegExp::operator !=(filter));
//m_UserModelProxy->invalidate();

Santosh Reddy
9th March 2017, 06:26
Use a custom QSortFilterProxyModel and implement


virtual bool filterAcceptsColumn(int source_column, const QModelIndex & source_parent) const
virtual bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const