[Qt-interest] Basic update() paint - more info
Phil
phillor at telstra.com
Wed Jan 28 02:33:06 CET 2009
On Tuesday 27 January 2009 13:18:06 andrew.m.goth at l-3com.com wrote:
>
> What do you mean when you say base class? Do you mean main application
> window class?
Yes and I've sub classed the main window to my base class under Kdevelop.
> What is the relationship between this base class and the Map class? Are
> they both derived from QWidget or a subclass thereof?
I've promoted the frame on the main window that was generated by Designer to
my Map class. Map's paint event correctly displays a map in the frame. No
problem there.
> What function does the above code appear in? Is it the base class
> constructor, its update() function, or something else?
The base class is supposed to pass parameters to the Map class where update()
should trigger the paint event. Update() is triggered but the paint function
is not working correctly. The following is a bit of Map class test code that
I'm trying to use to sort out the problem. The rectangle should alternate
between magenta and yellow each second; it's only displayed in magenta.
Let's go back to the begining, if I may, and assume that the Map class is
called correctly. This only leaves the paint event as the culprit. The
following is a bit of test code that initially did work.
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);
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);
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);
}
No doubt I'm stretching your patience and I've overlooked something very
basic.
--
Regards,
Phil.
More information about the Qt-interest-old
mailing list