Solved Problem in QTreeView
-
def apply_filter(self): """ Method for taking actions once filter combo box value is changed """ self.clear_tree_status( self.test_cases_model.itemFromIndex(self.test_cases_model.index(0, 0))) text_changed = self.stage_select_combobox.currentData() # change tab to select and run if view is on another tab if self.select_tests_tabwidget.currentIndex() != self.select_run_tab: self.select_tests_tabwidget.setCurrentIndex(self.select_run_tab) if text_changed: tag = text_changed.split("(")[0].strip() # test case filter pattern set as RegExp by default syntax = QtCore.QRegExp.PatternSyntax(QRegExp.RegExp) regexp = QRegExp(tag, Qt.CaseSensitive, syntax) self.filter_proxy_model.setFilterRegExp(regexp) # change tab to select and run if view is on another tab if self.select_tests_tabwidget.currentIndex() != self.select_run_tab: self.select_tests_tabwidget.setCurrentIndex(self.select_run_tab) # uncheck test case model based on filter tag change self.__uncheck_test_case_model_based_on_filtering() else: syntax = QRegExp.PatternSyntax() regexp = QRegExp("", Qt.CaseSensitive, syntax) self.filter_proxy_model.setFilterRegExp(regexp) # uncheck test case model based on filter tag change self.__uncheck_test_case_model_based_on_filtering()
-
QRegExp is deprecated, please use QRegularExpression and respective setters for model (those are provided as setFilterRegularExpression() ). From the looks of it you use QSortFilterProxyModel which has exactly that setter (you can supply pattern directly as a QString too).
My guess would be that you need something along this excerpt from the documentation link above:
QString p("a .*|pattern"); // re matches exactly the pattern string p QRegularExpression re(QRegularExpression::anchoredPattern(p));
Please take your time and read through whole docs of the class, that really pays off.
-
@artwaw Ok,thank you . I will try this.
-
This post is deleted! -
@Prathamesh fine-tune your regex. You can test options here https://regex101.com
-
@artwaw This works, setting regex to multi-line or ascii works, but how do i do that in my code. I have tried implementing it as regexp = QtCore.QRegExp.Multiline / QtCore.QRegExp.ASCII ,and then filter_proxy_model = QSortFilterProxyModel --> filter_proxy_model.setFilterRegExp(regexp),but it does not work. Am I missing something here or doing something wrong?
-
@Prathamesh for more information please re-read this post https://forum.qt.io/post/661925
-
@artwaw I have done some changes as highlighted below:- But those are not working.
- filter_proxy_model = QSortFilterProxyModel in below code
- setFilterRegExp(regexp) --> in this , regexp parameter is defining QRegularExpression class and multiline option for matching. But setFilterRegExp() method accepts only QRegExp class members/values. So, I have tried using setFilterRegularExpression() ,but this method does not seem to be present in our QRegularExpression class.
So now, is there any alternative for this? And please suggest if there are any mistakes in my code.
def apply_filter(self): """ Method for taking actions once filter combo box value is changed """ self.clear_tree_status( self.test_cases_model.itemFromIndex(self.test_cases_model.index(0, 0))) text_changed = self.stage_select_combobox.currentData() # change tab to select and run if view is on another tab if self.select_tests_tabwidget.currentIndex() != self.select_run_tab: self.select_tests_tabwidget.setCurrentIndex(self.select_run_tab) if text_changed: tag = text_changed.split("(")[0].strip() # test case filter pattern set as RegExp by default # syntax = QtCore.QRegExp.PatternSyntax(QRegExp.RegExp) # syntax = QtCore.QRegularExpression.MultilineOption # regexp = QRegExp(tag, Qt.CaseSensitive, syntax) **regexp = QtCore.QRegularExpression(tag, QtCore.QRegularExpression.MultilineOption)** self.filter_proxy_model.setFilterRegExp(regexp)**bolded text** # change tab to select and run if view is on another tab if self.select_tests_tabwidget.currentIndex() != self.select_run_tab: self.select_tests_tabwidget.setCurrentIndex(self.select_run_tab) # uncheck test case model based on filter tag change self.__uncheck_test_case_model_based_on_filtering()
-
@Prathamesh
in Problem in QTreeView:I have tried using setFilterRegularExpression() ,but this method does not seem to be present in our QRegularExpression class.
Because it is not.
setFilterRegularExpression()
is a method of QSortFilterProxyModel() - see this link please.I asked you to read the documentation of QSortFilterProxyModel twice and you didn't. Everything is there in plain text, I even quoted the excerpt from the said documentation that seems to hold solution to your problem.
-
@artwaw I have gone through it many times. I know according to the documentation , setFilterRegularExpression() method is a member of QSortFilterProxyModel,but it is not present in this class as well in the qt5 version which we have. Is it some kind of Qt version dependent? I mean is it included in latest version and it was not there in previous version? That is what my question was actually?
-
This property was introduced in Qt 5.12.
This quote is from the documentation you said you've read.
-
@artwaw Then it has to be present because we are using Qt 5.15. How is it even possible, I don't understand. Is there any way to handle it?