I used the code you gave me and just to try it I used an example given in the QPainter documentation:
{
paint.setPen(Qt::blue);
paint.drawText(rect(), Qt::AlignCenter, "The Text");
}
void TableGrid::paintEvent(QPaintEvent* event)
{
QTableWidget::paintEvent(event);
QPainter paint(this);
paint.setPen(Qt::blue);
paint.drawText(rect(), Qt::AlignCenter, "The Text");
}
To copy to clipboard, switch view to plain text mode
However, this gives me run-time warnings saying "QPainter::begin: Widget painting can only begin as a result of a paintEvent" yet it compiles just fine. This is the only place I have implemented any painting functions so this must be the cause. However, the error doesn't make any sense as the call is from within the paintEvent function.
It is not a problem with the code you gave me as it gives the same errors if I reduce the code to:
{
}
void TableGrid::paintEvent(QPaintEvent* event)
{
QPainter paint(this);
}
To copy to clipboard, switch view to plain text mode
So it is obviously being caused by the begin() call in the constructor which for some reason thinks it's not being called from a paintEvent function. Any ideas?
I don't know if this makes any difference but I'm using Qt 4.1 under Linux.
Bookmarks