PDA

View Full Version : QTableView and QAbstractTableModel programming



drmacro
22nd September 2016, 23:26
I have successfully created code that loads and displays data in a QTableView with a QAbstractTableModel.

I have done so by piecing together a LOT of bits from around the web. And I would really like to find some discussion of the concepts of table views and models...I really find the complexity of displaying a table of data with this construct mind numbing. I be happy to go read any recommendations. Or if anyone can recommend any tutorials or examples?

That said, what I really need to do now is add code that sets the color of a row. For example the color of the row indicates the function of the displayed data. So each row may be one of 4 or 5 colors.

So far, setBackgroundColor doesn't seem to be the answer...

I'm using PyQt5.

jefftee
23rd September 2016, 02:24
Look at QAbstractTableModel::data method, specifically for the Qt::BackgroundRole.

d_stranz
23rd September 2016, 17:49
I be happy to go read any recommendations.

Mark Summerfield's book "Advanced Qt Programming" has nearly 200 pages on models, views, delegates, and other things associated with the Model / View architecture. It is a few years old and is based on Qt4, but the M/V architecture is not much different in Qt5. Unfortunately, it is all C++, but the mapping to Python is not so hard.

He also has another book, "Rapid GUI Programming with Python and Qt", also PyQt4-based, but it does not have as much material on M/V.

He's a good author, books are easy to read and understand. I found the first book particularly helpful in understanding tree models, especially using them with proxies.