Results 1 to 4 of 4

Thread: QTable>>>paintCell

  1. #1
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default QTable>>>paintCell

    hello ppl,

    I have reimplemented paintCell, i want to give the cells of my table a color.. i have 10 cells and i want that the 5 cells should get a color.. like the first cell white and the second yellow and the third white, fourth yellow .....

    this is my code i am only able to color the 3 cells ...

    Qt Code:
    1. void myTable::paintCell(QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg)
    2. {
    3.  
    4. int numRows = this->numRows();
    5. int countRows = numRows;
    6.  
    7. for(int i = 0; i < numRows ; i++)
    8.  
    9. if (row == numRows-- || row == numRows+i || row == numRows-i || row == numRows+i
    10. || row ==numRows-i)
    11. {
    12. QColorGroup colorGroup(cg);
    13. colorGroup.setColor(QColorGroup::Base, QColor("#ffffbb"));
    14. QTable::paintCell(p, row, col, cr, selected, colorGroup);
    15. }
    16. else
    17. {
    18. QTable::paintCell(p, row, col, cr, selected, cg);
    19. }
    20.  
    21. }
    To copy to clipboard, switch view to plain text mode 

    can anyone take a look at the code?
    thanx in advance
    Love::Peace

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTable>>>paintCell

    Quote Originally Posted by :db:sStrong
    if (row == numRows-- || ...
    That -- looks very suspicious.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTable>>>paintCell

    You don't need the for loop:
    Qt Code:
    1. void myTable::paintCell(QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg)
    2. {
    3. QColorGroup colorGroup(cg);
    4. if( col % 2 == 1 ) {
    5. colorGroup.setColor(QColorGroup::Base, QColor("#ffffbb"));
    6. }
    7. QTable::paintCell(p, row, col, cr, selected, colorGroup);
    8. }
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to jacek for this useful post:

    :db:sStrong (25th July 2006)

  5. #4
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: QTable>>>paintCell

    oh yes, i made my life difficult by thinking difficult , u r right

    thanx alot....
    Love::Peace

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.