[PyQt] Selecting the last added item in a QAbstractTableModel

Brian Zambrano brianz at gmail.com
Thu Sep 9 06:04:28 BST 2010


You can do this with setCurrentIndex in the view.  You'll simply need to
select an index in the row you just added.

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qabstractitemview.html#setCurrentIndex

In your case, it may be something like:

# assume you have a reference to the view and model
self.model.insertRow(stuff)
indx = self.model.index(len(fFlist) - 1, 0)
self.view.setCurrentIndex(indx)

BZ



On Wed, Sep 8, 2010 at 3:52 PM, <AmFreak at web.de> wrote:

> Hi,
>
> i have a QAbstractTableModel in which i insert data (rows) with a button
> that opens a dialog and calls the insertRow method after the dialog is
> closed:
>
> def insertRow (self, row, filesystem, parent = QModelIndex() ):
>        self.beginInsertRows(QModelIndex(), len(self.fList),
> len(self.fList))
>        self.fList.append(filesystem)
>        self.endInsertRows()
>
> now the new data is added to the tableview and the view is sorted. But what
> bugs me is that the new row isn't selected (marked) - how can i do this ?
>
>
> Greetings
>
> AmFreak
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100908/f7323e3e/attachment.html>


More information about the PyQt mailing list