PDA

View Full Version : QTable>>>paintCell



:db:sStrong
25th July 2006, 10:01
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 ...


void myTable::paintCell(QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg)
{

int numRows = this->numRows();
int countRows = numRows;

for(int i = 0; i < numRows ; i++)

if (row == numRows-- || row == numRows+i || row == numRows-i || row == numRows+i
|| row ==numRows-i)
{
QColorGroup colorGroup(cg);
colorGroup.setColor(QColorGroup::Base, QColor("#ffffbb"));
QTable::paintCell(p, row, col, cr, selected, colorGroup);
}
else
{
QTable::paintCell(p, row, col, cr, selected, cg);
}

}


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

jacek
25th July 2006, 10:36
if (row == numRows-- || ...
That -- looks very suspicious.

jacek
25th July 2006, 10:40
You don't need the for loop:
void myTable::paintCell(QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg)
{
QColorGroup colorGroup(cg);
if( col % 2 == 1 ) {
colorGroup.setColor(QColorGroup::Base, QColor("#ffffbb"));
}
QTable::paintCell(p, row, col, cr, selected, colorGroup);
}

:db:sStrong
25th July 2006, 10:45
oh yes, i made my life difficult by thinking difficult , u r right :)

thanx alot....