How can I select a row when matching a QLineEdit string?

111 views Asked by At

I´m looking for a smart way to select a specific Row without using the curser or klick inside my QSqlTableModel. Instead I would like to use a QLineEdit.

So here is the function I´m using for my QLineEdit, which works well.

def update_filter_ID(self, s):
        s = re.sub(r'[\W_]+', "", s)
        filter_str = f"[Article Number] LIKE '%{s}%'".format(s)
        
        self.ui.model.setFilter(filter_str)
        self.ui.DB_View.selectRow(0)

self.ui.search_ID.textChanged.connect(self.update_filter_ID)

I also got a function to get information which ID the User has clicked:

def right_click_action(self):
        
        global current_row
        
        rows = self.ui.DB_View.selectionModel().selectedIndexes()
        current_row= self.ui.model.record(rows[0].row()).value(0)
        print(current_row)
        return current_row

Now I would like to combine the functions to let the model select the row, whenever the filter string is matching the ID.

I thought about making a List of ID´s and then compare the filter_str with a loop. But I would like to know, if there is a more elegant way to do so.

0

There are 0 answers