ModelView Autoselection

Heads up! You've already completed this tutorial.

Mohamad_Zakwan | 2020-05-07 18:29:29 UTC | #1

Anyone manage to get the autoselection working? I've been reading the document in qt official website, but could not find a direct explanation on how to do it. I manage to get auto-selection works, but it involves creating a QRect. I don't think that's the correct way.


Hank_Ericson | 2020-06-05 01:06:24 UTC | #2

Hi Mohamad,

You can get select by replacing the

python
self.todoView.clearSelection()

part with the following:

python
lastindex = self.model.index(len(self.model.todos)-1, 0)
self.todoView.setCurrentIndex(lastindex)

This will first get the last index as a QModelIndex from the model itself by specifying the last row (length - 1) and column 0 and then setting that index as the current index in the todoView.

The complete guide to packaging Python GUI applications with PyInstaller.
[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]

Hope this helps!


Virginia | 2020-05-07 18:32:41 UTC | #3

Create GUI Applications with Python & Qt6 by Martin Fitzpatrick — (PyQt6 Edition) The hands-on guide to making apps with Python — Over 10,000 copies sold!

More info Get the book

Thank you very much! I also had the same question and couldn't find enough information using web searches to figure it out. This is very helpful!


PyQt/PySide 1:1 Coaching with Martin Fitzpatrick — Get one on one help with your Python GUI projects. Working together with you I'll identify issues and suggest fixes, from bugs and usability to architecture and maintainability.

Book Now 60 mins ($195)

Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak
Martin Fitzpatrick

ModelView Autoselection was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt. Martin founded PythonGUIs to provide easy to follow GUI programming tutorials to the Python community. He has written a number of popular Python books on the subject.