Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem in QTreeView
Qt 6.11 is out! See what's new in the release blog

Problem in QTreeView

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • artwawA Offline
    artwawA Offline
    artwaw
    wrote on last edited by
    #4

    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.

    For more information please re-read.

    Kind Regards,
    Artur

    P 2 Replies Last reply
    1
    • artwawA artwaw

      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.

      P Offline
      P Offline
      Prathamesh
      wrote on last edited by
      #5

      @artwaw Ok,thank you . I will try this.

      1 Reply Last reply
      0
      • artwawA artwaw

        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.

        P Offline
        P Offline
        Prathamesh
        wrote on last edited by Prathamesh
        #6
        This post is deleted!
        artwawA 1 Reply Last reply
        0
        • P Prathamesh

          This post is deleted!

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by
          #7

          @Prathamesh fine-tune your regex. You can test options here https://regex101.com

          For more information please re-read.

          Kind Regards,
          Artur

          P 1 Reply Last reply
          1
          • artwawA artwaw

            @Prathamesh fine-tune your regex. You can test options here https://regex101.com

            P Offline
            P Offline
            Prathamesh
            wrote on last edited by
            #8

            @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?

            artwawA 1 Reply Last reply
            0
            • P Prathamesh

              @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?

              artwawA Offline
              artwawA Offline
              artwaw
              wrote on last edited by
              #9

              @Prathamesh for more information please re-read this post https://forum.qt.io/post/661925

              For more information please re-read.

              Kind Regards,
              Artur

              P 1 Reply Last reply
              2
              • artwawA artwaw

                @Prathamesh for more information please re-read this post https://forum.qt.io/post/661925

                P Offline
                P Offline
                Prathamesh
                wrote on last edited by
                #10

                @artwaw I have done some changes as highlighted below:- But those are not working.

                1. filter_proxy_model = QSortFilterProxyModel in below code
                2. 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()
                
                artwawA 1 Reply Last reply
                0
                • P Prathamesh

                  @artwaw I have done some changes as highlighted below:- But those are not working.

                  1. filter_proxy_model = QSortFilterProxyModel in below code
                  2. 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()
                  
                  artwawA Offline
                  artwawA Offline
                  artwaw
                  wrote on last edited by
                  #11

                  @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.

                  For more information please re-read.

                  Kind Regards,
                  Artur

                  P 1 Reply Last reply
                  1
                  • artwawA artwaw

                    @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.

                    P Offline
                    P Offline
                    Prathamesh
                    wrote on last edited by Prathamesh
                    #12

                    @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?

                    artwawA 1 Reply Last reply
                    0
                    • P Prathamesh

                      @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?

                      artwawA Offline
                      artwawA Offline
                      artwaw
                      wrote on last edited by artwaw
                      #13

                      @Prathamesh

                      This property was introduced in Qt 5.12.
                      

                      This quote is from the documentation you said you've read.

                      For more information please re-read.

                      Kind Regards,
                      Artur

                      P 1 Reply Last reply
                      1
                      • artwawA artwaw

                        @Prathamesh

                        This property was introduced in Qt 5.12.
                        

                        This quote is from the documentation you said you've read.

                        P Offline
                        P Offline
                        Prathamesh
                        wrote on last edited by
                        #14

                        @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?

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved