QGraphicsItem repaint

Posted by onurozcelik on Stack Overflow See other posts from Stack Overflow or by onurozcelik
Published on 2010-06-01T13:35:11Z Indexed on 2010/06/01 14:43 UTC
Read the original article Hit count: 271

Filed under:
|
|
|
|

I want to change text color inside a rectangle periyodically Here is my trial:

 TrainIdBox::TrainIdBox()
 {
   boxRect = QRectF(0,0,40,15);
   testPen = QPen(Qt:red);
   i=0;
   startTimer(500);
 }

QRectF TrainIdBox::boundingRect() const
{
 return boxRect;
}

void TrainIdBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,   QWidget *widget)
{
  Q_UNUSED(widget);
  Q_UNUSED(option);

  painter->setPen(QPen(drawingColor,2));
  painter->drawRect(boxRect);
  painter->setPen(testPen);
  painter->drawText(boxRect,Qt::AlignCenter,"TEST");

 }
 void TrainIdBox::timerEvent(QTimerEvent *te)
 {
  testPen = i % 2 == 0 ? QPen(Qt::green) : QPen(Qt::yellow);
  i++;
  update(boxRect);
 }

This code does not working properly. What is wrong?

© Stack Overflow or respective owner

Related posts about c++

Related posts about qt