Results 1 to 3 of 3

Thread: QTableView and QAbstractTableModel programming

  1. #1
    Join Date
    Oct 2015
    Posts
    45
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default QTableView and QAbstractTableModel programming

    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.

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QTableView and QAbstractTableModel programming

    Look at QAbstractTableModel::data method, specifically for the Qt::BackgroundRole.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,053
    Thanks
    233
    Thanked 649 Times in 639 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QTableView and QAbstractTableModel programming

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QAbstractTableModel, QTableView and restoreState.
    By cydside in forum Qt Programming
    Replies: 0
    Last Post: 10th August 2014, 11:41
  2. Replies: 3
    Last Post: 18th April 2014, 03:37
  3. Replies: 0
    Last Post: 5th April 2011, 16:51
  4. Performance with QTableView and QAbstractTableModel
    By MBex in forum Qt Programming
    Replies: 3
    Last Post: 25th February 2009, 08:04
  5. Replies: 3
    Last Post: 29th January 2009, 08:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.