Results 1 to 12 of 12

Thread: Color the rows in QTableView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Color the rows in QTableView

    if you use some of QSql*Model then you should approach which estanisgeyer suggested of write your own delegate.
    an exmaple
    Qt Code:
    1. class ColorDelegate: public QItemDelegate
    2. {
    3. public:
    4. ColorDelegate(QObject *parent = 0) : QItemDelegate(parent) {}
    5.  
    6. public:
    7. virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    8. {
    9. drawBackground(painter, option, index);
    10. QItemDelegate::paint(painter, option, index);
    11. }
    12.  
    13. protected:
    14. virtual void drawBackground(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    15. {
    16. Q_UNUSED(index);
    17. painter->fillRect(option.rect, QColor(qrand()%255, qrand()%255, qrand()%255));
    18. }
    19. };
    To copy to clipboard, switch view to plain text mode 
    applying a delegate for a table
    Qt Code:
    1. ...
    2. table->setItemDelegate(new ColorDelegate(table));
    3. ...
    To copy to clipboard, switch view to plain text mode 
    but in this case when a table is being resized items colors is being changed to.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  2. The following 2 users say thank you to spirit for this useful post:

    grub87 (17th June 2009), NicholasSmith (6th October 2010)

Similar Threads

  1. Set height of QTableView to fit exact number of rows.
    By Ben.Hines in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2019, 01:49
  2. Remove selected rows from a QTableView
    By niko in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2016, 12:49
  3. Count the number of rows in a QTableView
    By grub87 in forum Qt Programming
    Replies: 9
    Last Post: 28th June 2009, 16:31
  4. QTableView has constant number of rows
    By tomeks in forum Qt Programming
    Replies: 5
    Last Post: 10th December 2008, 15:29
  5. QTableView number of rows and scrollbar issue
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2006, 06:55

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