Results 1 to 10 of 10

Thread: Change SqlQueryModel QTableView's Row Color

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Change SqlQueryModel QTableView's Row Color

    Didn't include num rows or anything thing else...
    Right, because your QSqlQueryModel base class defines them. QAbstractTableModel defines these as pure virtual methods, and so any concrete class based on it needs to define at least the three methods: rowCount(), columnCount(), and data().

    By the way, I was curious how hard it would be to turn my example into one that uses a QSortFilterProxyModel instead of deriving from the actual model, and it turns out to be pretty simple. Doing so is really what the Qt Model-View architecture is intended for - you map the same model into different views using proxies to extract or modify parts of the model to suit the requirements of the view. This is generally preferred over deriving from the model (as you and I did) to accomplish the same end.

    Have to refresh the model when I change things
    Not sure what you mean by that. It is usually the model that notifies the view that it has changed, and the view updates accordingly. Unless you are changing something like the column used for the comparison or the row color; that's where you lose the connection to the model. If you used a QSortFilterProxyModel, you qould simply call the invalidate() method after changing something external to the model.
    Last edited by d_stranz; 16th September 2014 at 22:51.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Change SqlQueryModel QTableView's Row Color

    Quote Originally Posted by d_stranz View Post
    By the way, I was curious how hard it would be to turn my example into one that uses a QSortFilterProxyModel instead of deriving from the actual model, and it turns out to be pretty simple.
    Sounds actually more like a job for QIdentityProxyModel, the proxy only changes data, not structure.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    d_stranz (17th September 2014)

  4. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Change SqlQueryModel QTableView's Row Color

    QIdentityProxyModel
    Yes, even better. Too many darn classes in Qt to keep track of all of them. I'll keep this in mind the next time I need a proxy model.

Similar Threads

  1. Replies: 7
    Last Post: 25th July 2013, 21:47
  2. Replies: 7
    Last Post: 21st May 2013, 22:17
  3. Replies: 3
    Last Post: 22nd January 2010, 16:46
  4. how to change text color in QTableView?
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2008, 10:03
  5. QTableView change color of current Cell
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 4th March 2006, 11:22

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
  •  
Qt is a trademark of The Qt Company.