diff options
author | Andy Shaw <andy.shaw@qt.io> | 2021-07-13 11:24:08 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-07-14 09:19:07 +0000 |
commit | 1ec362aa10149423aa1e71443d500dd87b39614f (patch) | |
tree | a382b36b786418b61c8e57e8e174a70298ed7199 | |
parent | eeec277ba0e257e58609e96bef64b13d0272f3d5 (diff) |
When setting the line dash to be an empty array reset the style to Solid
An empty line dash array is indicating that it should be reset to be a
Solid line, otherwise it ends up reusing the previous settings for the
pen instead of drawing a solid line.
Fixes: QTBUG-75553
Change-Id: I16466672de95da8ef0cf3fc261969e7cc6add227
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
(cherry picked from commit c31638f16b1fe709dd9df232afb9ab7fac3b231e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp | 5 | ||||
-rw-r--r-- | tests/auto/quick/qquickcanvasitem/data/tst_line.qml | 31 |
2 files changed, 35 insertions, 1 deletions
diff --git a/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp b/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp index bfa18acc0e..498f1c6d40 100644 --- a/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp +++ b/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp @@ -375,7 +375,10 @@ void QQuickContext2DCommandBuffer::replay(QPainter* p, QQuickContext2D::State& s } state.lineDash = pattern; QPen nPen = p->pen(); - nPen.setDashPattern(pattern); + if (count > 0) + nPen.setDashPattern(pattern); + else + nPen.setStyle(Qt::SolidLine); p->setPen(nPen); break; } diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_line.qml b/tests/auto/quick/qquickcanvasitem/data/tst_line.qml index dc960a24d0..fb4db5ae54 100644 --- a/tests/auto/quick/qquickcanvasitem/data/tst_line.qml +++ b/tests/auto/quick/qquickcanvasitem/data/tst_line.qml @@ -894,6 +894,37 @@ CanvasTestCase { comparePixel(ctx, 39,0, 0,0,0,0); } + function test_lineDashReset(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.strokeStyle = "#ff0000"; + ctx.lineWidth = 2; + var pattern = [2, 3, 5, 1, 6, 3] + ctx.setLineDash(pattern) + + compare(ctx.getLineDash(), pattern); + + pattern = [] + ctx.setLineDash(pattern) + compare(ctx.getLineDash(), pattern); + + ctx.beginPath(); + ctx.moveTo(0, 0); + ctx.lineTo(40, 0); + ctx.stroke(); + + comparePixel(ctx, 0,0, 255,0,0,255); + comparePixel(ctx, 4,0, 255,0,0,255); + comparePixel(ctx, 5,0, 255,0,0,255); + comparePixel(ctx, 14,0, 255,0,0,255); + comparePixel(ctx, 20,0, 255,0,0,255); + comparePixel(ctx, 21,0, 255,0,0,255); + comparePixel(ctx, 22,0, 255,0,0,255); + comparePixel(ctx, 34,0, 255,0,0,255); + comparePixel(ctx, 35,0, 255,0,0,255); + } + function test_lineDashOffset(row) { var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d'); |