Note that there are some explanatory texts on larger screens.

plurals
  1. POArtifacts when trying to draw background grid without anti-aliasing in a QGraphicsScene
    primarykey
    data
    text
    <p>I'm trying to draw a background grid in the drawBackground() function of my QGraphicsScene subclass:</p> <pre><code>void Scene::drawBackground(QPainter *painter, const QRectF &amp;rect) { const int gridSize = 50; const int realLeft = static_cast&lt;int&gt;(std::floor(rect.left())); const int realRight = static_cast&lt;int&gt;(std::ceil(rect.right())); const int realTop = static_cast&lt;int&gt;(std::floor(rect.top())); const int realBottom = static_cast&lt;int&gt;(std::ceil(rect.bottom())); // Draw grid. const int firstLeftGridLine = realLeft - (realLeft % gridSize); const int firstTopGridLine = realTop - (realTop % gridSize); QVarLengthArray&lt;QLine, 100&gt; lines; for (qreal x = firstLeftGridLine; x &lt;= realRight; x += gridSize) lines.append(QLine(x, realTop, x, realBottom)); for (qreal y = firstTopGridLine; y &lt;= realBottom; y += gridSize) lines.append(QLine(realLeft, y, realRight, y)); //painter-&gt;setRenderHint(QPainter::Antialiasing); painter-&gt;setPen(QPen(QColor(220, 220, 220), 0.0)); painter-&gt;drawLines(lines.data(), lines.size()); // Draw axes. painter-&gt;setPen(QPen(Qt::lightGray, 0.0)); painter-&gt;drawLine(0, realTop, 0, realBottom); painter-&gt;drawLine(realLeft, 0, realRight, 0); } </code></pre> <p>However, unless I turn on anti-aliasing, moving items around will sometimes leave artifacts in the grid (areas where it's not drawn). It seems it mostly happens at low zoom levels, when the view is zoomed out a bit. Any ideas what I might be doing wrong here?</p> <p>I'd really don't want to turn anti-aliasing on since the lines are strictly horizontal and vertical, and I'd like them to be as crisp as possible.</p> <p>Any help is much appriciated, Regards, Elvis</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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