Calling value from model through pair of integers representing row and column

Heads up! You've already completed this tutorial.

David_Hansson | 2020-06-07 08:12:07 UTC | #1

Hi, if I want to call the value (as a string say) from the model (through a buttonclick from a pushbutton in the mainwidget), not through clicking in a cell in the QTableView but giving the information through a pair of integers. lets say row 0, column 0. Given the structure in the tutorial "Displaying tabular data in Qt5 ModelViews" https://www.pythonguis.com/courses/model-views/qtableview-modelviews-numpy-pandas/

I try value = self.model.data(0, 0, QModelIndex(), Qt.DisplayRole).toString()

But it doesnt work. (it crashes the app.)


scaracciolo | 2020-06-30 12:26:15 UTC | #2

Hi David!

You could try,

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

More info Get the book

Index = self.model.index(0, 0) value = self.model.data(index, Qt.DisplayRole)


David_Hansson | 2020-06-09 05:58:57 UTC | #3

Over 15,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt6
Take a look

Downloadable ebook (PDF, ePub) & Complete Source code

Also available from Leanpub and Amazon Paperback

[[ 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 ]]

This worked. Thank you.


Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.

More info Get the book

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

Calling value from model through pair of integers representing row and column 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.