[PyQt] Selecting the last added item in a QAbstractTableModel

AmFreak at web.de AmFreak at web.de
Fri Sep 10 02:40:00 BST 2010


Ok solved it :)

   		  index = self.model.index(len(self.fList) - 1, 0)
             sourceIndex = self.sortFilterModel.mapFromSource(index)
             sRow = sourceIndex.row()
             self.view.selectRow(sRow)






> Thanks for the answer, but that doesn't work, cause the list is  
> automatically sorted when i put something in cause i have a  
> QSortFilterProxyModel() between the view and the model (sry i forgot to  
> mention that, don't hurt me :(   ), so the last element in the list  
> isn't the right one.
>
>
>
>
>
>> 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


More information about the PyQt mailing list