Skip to content
Permalink
Browse files

Workaround odd upstream Qt issue where a painter with a semi-transparent

brush with no solid pattern incorrectly applies the brush opacity to
the pen when exporting to printer devices

Fixes #36580
  • Loading branch information
nyalldawson committed May 20, 2020
1 parent 150b373 commit 38c82187a65d8b4833f2c633a69a4d937a8725eb
Showing with 27 additions and 4 deletions.
  1. +27 −4 src/core/symbology/qgsfillsymbollayer.cpp
@@ -41,6 +41,10 @@
#include <QDomElement>
#include <random>

#ifndef QT_NO_PRINTER
#include <QPrinter>
#endif

QgsSimpleFillSymbolLayer::QgsSimpleFillSymbolLayer( const QColor &color, Qt::BrushStyle style, const QColor &strokeColor, Qt::PenStyle strokeStyle, double strokeWidth,
Qt::PenJoinStyle penJoinStyle )
: mBrushStyle( style )
@@ -273,9 +277,6 @@ void QgsSimpleFillSymbolLayer::renderPolygon( const QPolygonF &points, const QVe

applyDataDefinedSymbology( context, mBrush, mPen, mSelPen );

p->setBrush( context.selected() ? mSelBrush : mBrush );
p->setPen( context.selected() ? mSelPen : mPen );

QPointF offset;
if ( !mOffset.isNull() )
{
@@ -284,7 +285,29 @@ void QgsSimpleFillSymbolLayer::renderPolygon( const QPolygonF &points, const QVe
p->translate( offset );
}

_renderPolygon( p, points, rings, context );
#ifndef QT_NO_PRINTER
if ( mBrush.style() == Qt::SolidPattern || mBrush.style() == Qt::NoBrush || !dynamic_cast<QPrinter *>( p->device() ) )
#endif
{
p->setPen( context.selected() ? mSelPen : mPen );
p->setBrush( context.selected() ? mSelBrush : mBrush );
_renderPolygon( p, points, rings, context );
}
#ifndef QT_NO_PRINTER
else
{
// workaround upstream issue https://github.com/qgis/QGIS/issues/36580
// when a non-solid brush is set with opacity, the opacity incorrectly applies to the pen
// when exporting to PDF/print devices
p->setBrush( context.selected() ? mSelBrush : mBrush );
p->setPen( Qt::NoPen );
_renderPolygon( p, points, rings, context );

p->setPen( context.selected() ? mSelPen : mPen );
p->setBrush( Qt::NoBrush );
_renderPolygon( p, points, rings, context );
}
#endif

if ( !mOffset.isNull() )
{

0 comments on commit 38c8218

Please sign in to comment.
You can’t perform that action at this time.