Show only Icon in QTableview cell

Heads up! You've already completed this tutorial.

nskd | 2021-04-13 06:52:05 UTC | #1

Hi,

I am starting out on learning pyQT5 and building an app that require the use of QTableview. I need help to understand how I can suppress the text or Boolean values, and just display the icons in the cell of QTableView.

I will be grateful if someone can show me a working model of how it works. With a working model, I believe I can understand the code and how things works. Thanks.

image|561x500


Salem_Bream | 2021-04-18 02:49:34 UTC | #2

you need to change the DisplayTole data returned from the model..

1:1 Coaching & Tutoring for your Python GUIs project
Martin Fitzpatrick Python GUIs Coaching & Training
60 mins ($195) Book Now

1:1 Python GUIs Coaching & Training

Comprehensive code reviewBugfixes & improvements • Maintainability advice and architecture improvements • Design and usability assessment • Suggestions and tips to expand your knowledgePackaging and distribution help for Windows, Mac & Linux • Find out more.

add these 2 lines to data function:

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

More info Get the book

python
if role==Qt.DisplayRole and isinstance(self._data[index.row(), index.column()], bool):
    return None

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

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

Show only Icon in QTableview cell 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.