Note that there are some explanatory texts on larger screens.

plurals
  1. PODerived QPainterPath, QPainter performance degrading quickly
    primarykey
    data
    text
    <p>I am currently trying to encapsulate my QPainter objects into reusable classes, possibly deriving each other. This enables them to transform the painter around any way they like, have their own children to draw etc:</p> <p>I have <code>DrawArc</code> derived from <code>QPainterPath</code></p> <pre><code>DrawArc::DrawArc() : QPainterPath() {} void DrawArc::paint(QPainter* painter) { painter-&gt;save(); //... arcTo(/*...*/); lineTo(/*...*/); painter-&gt;translate(QPoint(100,100)); painter-&gt;drawPath(*dynamic_cast&lt;QPainterPath*&gt;(this)); painter-&gt;restore(); } </code></pre> <p>and <code>DrawBeam</code> derived from <code>DrawArc</code></p> <pre><code>DrawBeam::DrawBeam() : DrawArc() {} void DrawBeam::paint(QPainter* painter) { painter-&gt;save(); //... painter-&gt;setPen(QPen(color, 4)); painter-&gt;setBrush(brush); DrawArc::paint(painter); painter-&gt;restore(); } </code></pre> <p>In the actual Widget I am doing the following</p> <pre><code>BeamWidget::BeamWidget(QWidget* parent) : QWidget(parent) { DrawBeam* mybeam = new DrawBeam(); } void BeamWidget::paintEvent(QPaintEvent * /* event */) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); mybeam-&gt;paint(&amp;painter); } </code></pre> <p>However I am seeing dramatic performance losses in <code>painter-&gt;drawPath(*dynamic_cast&lt;QPainterPath*&gt;(this));</code> after a few seconds (or few hundred redraws). Everything else in the remaining procedure seems to run fine but when I enable that line the performance degrades quickly.</p> <p>Also all elements deriving from <code>DrawArc</code> painting seem to sometimes lose their QBrush styles and remain visible even though <code>setAutoFillBackground(true);</code> is set...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload