I think the problem is your QPainter initialization.
You could just create a QPainter response as in hydraulic systems, it would look like this:
class PointDrawer: public QWidget { Q_OBJECT public: PointDrawer(QWidget* obj=0): QWidget(obj) {} virtual void paintEvent(QPaintEvent*) { QPainter p(this) p.setPen(QPen(Qt::black, 3)); int n = 8; while(...) { qreal fAngle = 2 * 3.14 * i / n; qreal x = 50 + cos(fAngle) * 40; qreal y = 50 + sin(fAngle) * 40; p.drawPoint(QPointF(x, y)); i++; } } }
It can also use something like this, but I do not recommend it (I just prefer a different solution):
class PointDrawer: public QWidget { Q_OBJECT private: QPainter p; public: PointDrawer(QWidget* obj=0): QWidget(obj) {} virtual void paintEvent(QPaintEvent*) { p.begin(this); p.setPen(QPen(Qt::black, 3)); int n = 8; while(...) { qreal fAngle = 2 * 3.14 * i / n; qreal x = 50 + cos(fAngle) * 40; qreal y = 50 + sin(fAngle) * 40; p.drawPoint(QPointF(x, y)); i++; } p.end(); } }
In the second example, calls to QPainter::begin(this) and QPainter::end() needed. In the first example, you can think of QPainter::begin(this) called in the constructor, and QPainter::end() in the destructor
For this reason, I assume: Since QPaintDevice usually duplicated in QT4, QPainter::end() may be where the image is transferred to graphics memory.
Caotic
source share