[Qt-interest] Basic update() paint - more info

andrew.m.goth at l-3com.com andrew.m.goth at l-3com.com
Fri Jan 30 00:36:11 CET 2009


Phil wrote:
> The paint event is called each second verified by the beep 
> sound and qDebug() displays beep's value and the colour name 
> correctly. The rectangle is only displayed in magenta, not 
> yellow each alternate second as it should be.
> 
> This is part of Map's constructor:
> {
>   QTimer *timer = new QTimer(this);
>   timer = new QTimer(this);

Twice?

>   connect(timer, SIGNAL(timeout()), this, SLOT(update()));
>   timer->start(1000);
> }
> 
> void Map::paintEvent(QPaintEvent *)
> {
>   QPainter paint(this);
>   blinkCursor(&paint);
> 
>   QApplication::beep(); 
> }
> 
> void Map::blinkCursor(QPainter *p)
> {
>   int static blink;
> 
>   if(blink == 0)
>   {
>     p->setPen(Qt::magenta);

In Qt 4.4.3, setPen() takes a QColor, not a Qt::GlobalColor.  Is a
QColor automatically being constructed?

By the way, are you getting any warnings when you compile this code?

>     blink = 1;
>     qDebug() << "blink = " << blink << "magenta" << endl;
>   }
> 
>   else
>   {
>     p->setPen(Qt::yellow);
>     blink = 0;
>     qDebug() << "blink = " << blink << "yelow" << endl;
>   }
> 
>   p->drawRect(500, 200, 20, 20);
> }

What happens if you vary the position and size of the rectangle?  Try
making it draw to a different place every update.

-- 
Andy Goth
<amgoth at link.com>




More information about the Qt-interest-old mailing list