Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. how to put a list inside a QRegExp
Qt 6.11 is out! See what's new in the release blog

how to put a list inside a QRegExp

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 2 Posters 1.4k Views
  • 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.
  • A Offline
    A Offline
    adrian88888888
    wrote on last edited by adrian88888888
    #1

    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 documentation

    Thanks

    JonBJ 1 Reply Last reply
    0
    • A adrian88888888

      @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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #6

      @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 setFilterRegExpression not setFilterRegExp like you still show. I did already say this, you need to look through your code.

      1 Reply Last reply
      1
      • A adrian88888888

        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 documentation

        Thanks

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @adrian88888888
        Don't use QRegExp anything, it's outdated. Use Qt's QRegularExpression, 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).

        A 1 Reply Last reply
        2
        • JonBJ JonB

          @adrian88888888
          Don't use QRegExp anything, it's outdated. Use Qt's QRegularExpression, 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).

          A Offline
          A Offline
          adrian88888888
          wrote on last edited by
          #3

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

          JonBJ 1 Reply Last reply
          0
          • A adrian88888888

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

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @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, and QRegularExpression accepts a string. There are examples of regular expressions on the QRegularExpression docs 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.

            A 1 Reply Last reply
            1
            • JonBJ JonB

              @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, and QRegularExpression accepts a string. There are examples of regular expressions on the QRegularExpression docs 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.

              A Offline
              A Offline
              adrian88888888
              wrote on last edited by
              #5

              @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

              JonBJ 1 Reply Last reply
              0
              • A adrian88888888

                @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

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #6

                @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 setFilterRegExpression not setFilterRegExp like you still show. I did already say this, you need to look through your code.

                1 Reply Last reply
                1

                • Login

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