PDA

View Full Version : To fill diagnol of the table with the color other than the whole table.



merry
21st June 2007, 09:45
Hi all
I m having a table or say matrix of 16 rows and 16 columns on the widget ,
on the widget there is also a qPushButton.

When i click on the button the Timer starts and the whole tabe starts filling with the color say red,
but i want the whole table fills with the red color except diagnol that is diagnol of the table fills with the different color say blue; How can I do this.

Pls help


Thanx

guilugi
21st June 2007, 10:20
Well, maybe I don't understand well, but you just have to do a test before you repaint your cells, something like this :

i -> row index
j -> column index

if i=j, set your color to blue
else, set it to red.

Am I wrong ?

merry
21st June 2007, 10:55
Hi

Might be u right , But i tried it remains unchanged
ok take a look at the paint event I used and tell me in that where should I used this



void CharacterWidget::paintEvent(QPaintEvent *ev)
{
QPainter p(this);
QColor c;
QBrush b;
b.setStyle (Qt::Dense2Pattern);
b.setColor(c);
p.setBrush(b);

int coox = 0;
int cooy = 0;


for(int curr = 0; curr<= m_max; curr++)
{
if(m_value+1==curr)
p.setBrush(Qt::white);
p.setPen(Qt::cyan);
p.drawRect(coox,cooy, squareSize, squareSize);
QRectF rectangle(coox,cooy,squareSize, squareSize);
coox += 16;
if(coox+16>width())
{
coox = 0;
cooy += 16;
}

}

}

guilugi
21st June 2007, 11:01
Oh, ok, you've designed your own table widget, right ?

I mean, you're not using QTableWidget / QTableView ?

merry
21st June 2007, 11:06
Yaa I m not using QTableWidget/QTable View

I m designing my own Table.

So If u have any soln then pls tell me

Thanx

guilugi
21st June 2007, 11:12
Okay, the problem is quite different then :)

You may add the same kind of test, it should work.
This test will be within your 'for' instruction



if (coox == cooy)
{
p.setBrush(Qt::white);
p.setPen(Qt::blue);
}

merry
21st June 2007, 11:21
It wont works yaar....

guilugi
21st June 2007, 11:22
Can you give me a sample code, so I can try to figure it out here ?

merry
21st June 2007, 11:26
pls review the code..


#include "characterwidget.h"

int coox ;
int cooy ;


QSize CharacterWidget::sizeHint() const
{
return QSize(m_max, m_max);
}

void CharacterWidget::paintEvent(QPaintEvent *ev)
{
QPainter p(this);
QColor c;
QBrush b; //(Qt::cyan,Qt::ConicalGradientPattern)
b.setStyle (Qt::Dense2Pattern);
b.setColor(c); //Qt::cyan
p.setBrush(b);

coox = 0;
cooy = 0;
for(int curr = 0; curr<= m_max; curr++)
{
if(m_value+1==curr)
p.setBrush(Qt::white);
p.setPen(Qt::cyan);
p.drawRect(coox,cooy, squareSize, squareSize);
QRectF rectangle(coox,cooy,squareSize, squareSize);
coox += 16;
if(coox+16>width())
{
coox = 0;
cooy += 16;
}

}

}

void CharacterWidget::timerEvent(QTimerEvent *ev)
{
if(ev->timerId()!=m_tim) return QWidget::timerEvent(ev);
m_value++;
update();
if(m_value>=m_max)
{
stop();
}
}

void CharacterWidget::setMax(int m)
{
m_max = m;
updateGeometry();
}
void CharacterWidget::setMin(int min)
{
m_min = min;
updateGeometry();
}


void CharacterWidget::start()
{
m_tim = startTimer(300);
}
void CharacterWidget::stop()
{
killTimer(m_tim);
m_tim = -1;
}

void CharacterWidget::FillColor()
{
flag=true;
start();
update();
}


If u understand this then tell me the soln.

guilugi
21st June 2007, 11:27
Well, I meant a compilable one, so I can test it directly on my computer :)