[graphics/krita] libs/ui/tool: Fix flickering when moving sampler from outside of canvas to inside

Emmet O'Neill <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit fde5d5b1e6f97c039a33ff285f6777abb52f6153 by Emmet O'Neill, on behalf of Dat Le.
Committed on 13/08/2026 at 23:16.
Pushed by emmetoneill into branch 'master'.

Fix flickering when moving sampler from outside of canvas to inside

M  +9    -4    libs/ui/tool/KisAsyncColorSamplerHelper.cpp

https://invent.kde.org/graphics/krita/-/commit/fde5d5b1e6f97c039a33ff285f6777abb52f6153

diff --git a/libs/ui/tool/KisAsyncColorSamplerHelper.cpp b/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
index 8dd11defc2c..a38004d4048 100644
--- a/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
+++ b/libs/ui/tool/KisAsyncColorSamplerHelper.cpp
@@ -84,6 +84,7 @@ struct KisAsyncColorSamplerHelper::Private
     int cacheCirclePreviewDiameter;
     bool canvasPreviewFetchingStarted {false};
     QRect oldCanvasPixelRect;
+    bool zoomPreviewHasPainted {false};
 
     QColor currentColor;
     QColor baseColor;
@@ -415,6 +416,7 @@ void KisAsyncColorSamplerHelper::deactivate()
     m_d->cacheCanvasPreviewRect = QRect();
     m_d->canvasPreviewFetchingStarted = false;
     m_d->oldCanvasPixelRect = QRect();
+    m_d->zoomPreviewHasPainted = false;
 
     m_d->isActive = false;
 
@@ -674,11 +676,12 @@ void KisAsyncColorSamplerHelper::paintCircle(QPainter &gc,
         zoomDocRectF.setSize(zoomDocRectF.size() / m_d->circleZoomPreviewScale);
         zoomDocRectF.moveCenter(m_d->sampleDocPoint);
 
-        bool isPainted = paintCircleCanvasPreview(cachePainter, cacheRect, zoomDocRectF, tf.map(m_d->cacheCircleInnerClip));
+        bool canvasPainted = paintCircleCanvasPreview(cachePainter, cacheRect, zoomDocRectF, tf.map(m_d->cacheCircleInnerClip));
 
-        // This is only false for the very first frame, when canvas preview is not yet available, leave the center hollow for better visual
-        // the gray flickering otherwise would be an eyesore
-        if (isPainted) {
+        // canvasPainted is false when canvas preview is not yet available, leave the center hollow for better visual
+        // When draging from the outside (or from ref image only) to canvas, canvasPainted can also be false, causing flickering on the already painted zoom preview
+        // So if preview was ever successfully render, don't hide these and cause flickering
+        if (canvasPainted || m_d->zoomPreviewHasPainted) {
             paintCircleReferenceImagePreview(cachePainter, cacheRect, zoomDocRectF, tf.map(m_d->cacheCircleInnerClip));
 
             // Draw crosshair if preview is offseted
@@ -689,6 +692,8 @@ void KisAsyncColorSamplerHelper::paintCircle(QPainter &gc,
             // Fill empty spaces to hide the underlying canvas
             cachePainter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
             cachePainter.drawPath(tf.map(m_d->cacheCircleInnerClip));
+
+            m_d->zoomPreviewHasPainted = true;
         }
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.