[PyQt] Searching method for QTableVew

Nick Gaens mail at nickgaens.com
Tue May 4 09:03:58 BST 2010


I would take a look at QTableWidget instead of QTableView.

For such a tableWidget:

def highlightResults(self, enteredText):
    for row in xrange(0, tableWidget.rowCount()):
        tableWidgetItem = tableWidget.item(row, 0) # Second argument is
column
        if tableWidgetItem.text().contains(enteredText):
            tableWidgetItem.setBackground(QBrush(Qt.blue))


Also, connect the lineEdit's textChanged signal to the method above like
this:

lineEdit.textChanged.connect(self.highlightResults)


On Tue, May 4, 2010 at 1:49 AM, AON LAZIO <aonlazio at gmail.com> wrote:

> Hi,
>     Suppose I want to search for some elements in QTableView when I type
> into a lineedit box. How can I locate the item in the table (The table
> direcly highlight the items searched if found)
>     Which method should I use?
>     Thanks in advance
>
> Aonlazio
>
> --
> Passion is my style
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



-- 
Nick Gaens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100504/9bedddb5/attachment.html>


More information about the PyQt mailing list