PDA

View Full Version : About painting



Pang
28th March 2007, 04:14
HI:
When I painting something on a widget i get such information "QPainter::begin: Widget painting can only begin as a result of a paintEvent" but i get what i want to paint. What does that information mean and how to avoid such information? thanks a lot

vermarajeev
28th March 2007, 05:20
HI:
When I painting something on a widget i get such information "QPainter::begin: Widget painting can only begin as a result of a paintEvent" but i get what i want to paint. What does that information mean and how to avoid such information? thanks a lot

According to the document


Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent widget attribute is set. On Mac OS X and Windows, you can only paint in a paintEvent() function regardless of this attribute's setting.

aamer4yu
28th March 2007, 06:13
To avoid the problem, u need to override the paintEvent , and do all the painting in that function.

Eldritch
28th March 2007, 18:21
You should override paintEvent() and put your drawing code in there. If you need to paint at some arbitrary point in time, and not rely on the more asynchronous nature of QWidget::update(), you can call QWidget::repaint() (choose a reasonable version to avoid repainting the entire window). It sends a paint event to the widget synchronously.