cwomeijer
4th September 2006, 17:29
Hi Everyone,
I seem to have some odd behaviour I can't explain.
Here is my code:
void ScribbleArea::drawGrid()
{
QPainter painter(&image);
painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin));
for(int y=0; y<image.height(); y+=gridSize)
for(int x=0; x<image.width(); x+=gridSize)
painter.drawPoint(x,y);
}
void ScribbleArea::drawPolygon()
{
QPainter painter(&image);
painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin));
#if 0
drawGrid();
#else
for(int y=0; y<image.height(); y+=gridSize)
for(int x=0; x<image.width(); x+=gridSize)
painter.drawPoint(x,y);
#endif
painter.drawLine(myPolygon);
modified = true;
}
void ScribbleArea::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
painter.drawImage(QPoint(0, 0), image);
}
Please note that this code copied from the scribble example!
Anyway I wanted to add my own grid drawing routine
Which seems to work just fine when called seperatly.
However if drawPolygon() calls drawGrid() the grid never shows
up. I do get to the routine but I simply don't see the grid drawn.
If I copy the routine into the drawPolygon() (see the #if 0)
then it does work.
Can someone explain this?
Regards
Otto
I seem to have some odd behaviour I can't explain.
Here is my code:
void ScribbleArea::drawGrid()
{
QPainter painter(&image);
painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin));
for(int y=0; y<image.height(); y+=gridSize)
for(int x=0; x<image.width(); x+=gridSize)
painter.drawPoint(x,y);
}
void ScribbleArea::drawPolygon()
{
QPainter painter(&image);
painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin));
#if 0
drawGrid();
#else
for(int y=0; y<image.height(); y+=gridSize)
for(int x=0; x<image.width(); x+=gridSize)
painter.drawPoint(x,y);
#endif
painter.drawLine(myPolygon);
modified = true;
}
void ScribbleArea::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
painter.drawImage(QPoint(0, 0), image);
}
Please note that this code copied from the scribble example!
Anyway I wanted to add my own grid drawing routine
Which seems to work just fine when called seperatly.
However if drawPolygon() calls drawGrid() the grid never shows
up. I do get to the routine but I simply don't see the grid drawn.
If I copy the routine into the drawPolygon() (see the #if 0)
then it does work.
Can someone explain this?
Regards
Otto