Вопрос

The common use of QPainter is inside a widget's paint event: Construct and customize (e.g. set the pen or the brush) the painter. Then draw. Remember to destroy the QPainter object after drawing.

This is from QPainter Class Reference. What if I create a QPainter object in constructor and use in in paintEvent. Has this any hidden problems or all will be ok? It is needed in my program to pass QPainter to another Painter object. All the painting is done paintEvent of course.

Это было полезно?

Решение

Yes, you can create a QPainter object in the constructor of your class for later use in functions of your class. You will then have to call the begin() and end() functions of QPainter before and after you paint with it, this is to associate the painter with a QPaintDevice and to release any resources allocated during painting.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top