how to put a list inside a QRegExp
-
Hi!
i have this list:
filter_list = ['blue', 'red', 'orange']and i want to place that list inside a
QRegExp, but this does not work:(QRegExp(filter_list))how i archive it? I want to put more than one item inside
QRegExp, i can't find it in the documentationThanks
-
@JonB its being 26 days(according to github) and all i wanted was to make a table that sorted stuff, im doing desperate questions because i'm getting desperate, i should read the docs instead, or use google more, or read your answers carefully
i surrender, thanks for the patience, i will see what i do in a couple days when i recover my dignity
@adrian88888888
It's OK :)self.ui.model_sorted.setFilterRegExp(QRegularExpression("album"|"golden"))Here all you want is:
self.ui.model_sorted.setFilterRegExpression(QRegularExpression("(album|golden)"))Just a Python string of:
"(album|golden)". Or for the rest of them:"(album|golden|check|no100|trash)".However, please note you should be using
setFilterRegExpressionnotsetFilterRegExplike you still show. I did already say this, you need to look through your code. -
Hi!
i have this list:
filter_list = ['blue', 'red', 'orange']and i want to place that list inside a
QRegExp, but this does not work:(QRegExp(filter_list))how i archive it? I want to put more than one item inside
QRegExp, i can't find it in the documentationThanks
@adrian88888888
Don't useQRegExpanything, it's outdated. Use Qt'sQRegularExpression, or use Python's regular expressions if you prefer where it's not required by Qt.You don't put lists in regular expressions. You put a string which is a pattern. So don't know what you mean here?
If what you mean is you want a regular expression which matches any of the list items you show, that would be
(blue|red|orange). -
@adrian88888888
Don't useQRegExpanything, it's outdated. Use Qt'sQRegularExpression, or use Python's regular expressions if you prefer where it's not required by Qt.You don't put lists in regular expressions. You put a string which is a pattern. So don't know what you mean here?
If what you mean is you want a regular expression which matches any of the list items you show, that would be
(blue|red|orange).@JonB im trying to match the items that i mark in the buttons
https://i.imgur.com/zAExz0v.gif
here its the code:
def SetFilter(self): filter_list = [] if self.ui.button_SetFilterAlbum.isChecked(): filter_list.append('album') if self.ui.button_SetFilterGolden.isChecked(): filter_list.append('golden') if self.ui.button_SetFilterCheck.isChecked(): filter_list.append('check') if self.ui.button_SetFilterNo100.isChecked(): filter_list.append('no100') if self.ui.button_SetFilterTrash.isChecked(): filter_list.append('trash') if len(filter_list) < 1: filter_list = ['album', 'golden', 'check', 'no100', 'trash'] print('matching in the model:',filter_list) self.ui.model_sorted.setFilterRegExp(QRegularExpression("album"|"golden"))the last line it's the one you suggest, but it gives an error, you have any ideas?
-
@JonB im trying to match the items that i mark in the buttons
https://i.imgur.com/zAExz0v.gif
here its the code:
def SetFilter(self): filter_list = [] if self.ui.button_SetFilterAlbum.isChecked(): filter_list.append('album') if self.ui.button_SetFilterGolden.isChecked(): filter_list.append('golden') if self.ui.button_SetFilterCheck.isChecked(): filter_list.append('check') if self.ui.button_SetFilterNo100.isChecked(): filter_list.append('no100') if self.ui.button_SetFilterTrash.isChecked(): filter_list.append('trash') if len(filter_list) < 1: filter_list = ['album', 'golden', 'check', 'no100', 'trash'] print('matching in the model:',filter_list) self.ui.model_sorted.setFilterRegExp(QRegularExpression("album"|"golden"))the last line it's the one you suggest, but it gives an error, you have any ideas?
@adrian88888888 said in how to put a list inside a QRegExp:
but it gives an error, you have any ideas?
The first idea I would have is to say what the error is and when it occurs.
self.ui.model_sorted.setFilterRegExp(QRegularExpression("album"|"golden"))"album"|"golden"is not a legitimate anything in Python. A regular expression is a string, andQRegularExpressionaccepts a string. There are examples of regular expressions on theQRegularExpressiondocs page and all over the web. I showed above what the regular expression you want looks like.I don't mean to be mean, but you really should understand this. Please have a think and try again.
-
@adrian88888888 said in how to put a list inside a QRegExp:
but it gives an error, you have any ideas?
The first idea I would have is to say what the error is and when it occurs.
self.ui.model_sorted.setFilterRegExp(QRegularExpression("album"|"golden"))"album"|"golden"is not a legitimate anything in Python. A regular expression is a string, andQRegularExpressionaccepts a string. There are examples of regular expressions on theQRegularExpressiondocs page and all over the web. I showed above what the regular expression you want looks like.I don't mean to be mean, but you really should understand this. Please have a think and try again.
@JonB its being 26 days(according to github) and all i wanted was to make a table that sorted stuff, im doing desperate questions because i'm getting desperate, i should read the docs instead, or use google more, or read your answers carefully
i surrender, thanks for the patience, i will see what i do in a couple days when i recover my dignity
-
@JonB its being 26 days(according to github) and all i wanted was to make a table that sorted stuff, im doing desperate questions because i'm getting desperate, i should read the docs instead, or use google more, or read your answers carefully
i surrender, thanks for the patience, i will see what i do in a couple days when i recover my dignity
@adrian88888888
It's OK :)self.ui.model_sorted.setFilterRegExp(QRegularExpression("album"|"golden"))Here all you want is:
self.ui.model_sorted.setFilterRegExpression(QRegularExpression("(album|golden)"))Just a Python string of:
"(album|golden)". Or for the rest of them:"(album|golden|check|no100|trash)".However, please note you should be using
setFilterRegExpressionnotsetFilterRegExplike you still show. I did already say this, you need to look through your code.