Skip to content

Commit 3e92e16

Browse files
committed
Fix page shadow drawing
1 parent 8fa173b commit 3e92e16

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/core/layout/qgslayoutitempage.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ QgsLayoutItemPage::QgsLayoutItemPage( QgsLayout *layout )
2828
setFlag( QGraphicsItem::ItemIsSelectable, false );
2929
setFlag( QGraphicsItem::ItemIsMovable, false );
3030
setZValue( QgsLayout::ZPage );
31+
32+
// bit hacky - we set a big hidden pen to avoid Qt clipping out the cosmetic shadow for the page
33+
// Unfortunately it's possible to adapt the item's bounding rect based on the view's transform, so it's
34+
// impossible to have a pixel based bounding rect. Instead we just set a big pen to force the page's
35+
// bounding rect to be kinda large enough to handle the shadow at most zoom levels...
36+
QPen shadowPen( QBrush( Qt::transparent ), 30 );
37+
shadowPen.setCosmetic( true );
38+
setPen( shadowPen );
3139
}
3240

3341
void QgsLayoutItemPage::setPageSize( const QgsLayoutSize &size )
@@ -121,17 +129,20 @@ void QgsLayoutItemPage::draw( QgsRenderContext &context, const QStyleOptionGraph
121129
//still possible to tell where pages with a transparent style begin and end
122130
painter->setRenderHint( QPainter::Antialiasing, false );
123131

132+
QRectF pageRect = QRectF( 0, 0, scale * rect().width(), scale * rect().height() );
133+
124134
//shadow
125135
painter->setBrush( QBrush( QColor( 150, 150, 150 ) ) );
126136
painter->setPen( Qt::NoPen );
127-
painter->drawRect( QRectF( SHADOW_WIDTH_PIXELS, SHADOW_WIDTH_PIXELS, rect().width() * scale + SHADOW_WIDTH_PIXELS, rect().height() * scale + SHADOW_WIDTH_PIXELS ) );
137+
painter->drawRect( pageRect.translated( SHADOW_WIDTH_PIXELS, SHADOW_WIDTH_PIXELS ) );
128138

129139
//page area
130140
painter->setBrush( QColor( 215, 215, 215 ) );
131141
QPen pagePen = QPen( QColor( 100, 100, 100 ), 0 );
142+
pagePen.setJoinStyle( Qt::MiterJoin );
132143
pagePen.setCosmetic( true );
133144
painter->setPen( pagePen );
134-
painter->drawRect( QRectF( 0, 0, scale * rect().width(), scale * rect().height() ) );
145+
painter->drawRect( pageRect );
135146
}
136147

137148
std::unique_ptr< QgsFillSymbol > symbol( mLayout->pageCollection()->pageStyleSymbol()->clone() );

0 commit comments

Comments
 (0)