Skip to content

Commit 530397c

Browse files
committed
[layouts] Fix legend does not respect anchor point when resizing
based on map content Fixes #19987
1 parent 46b6ffa commit 530397c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/core/layout/qgslayoutitemlegend.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,23 @@ void QgsLayoutItemLegend::paint( QPainter *painter, const QStyleOptionGraphicsIt
106106
if ( mForceResize )
107107
{
108108
mForceResize = false;
109+
109110
//set new rect, respecting position mode and data defined size/position
110-
QRectF targetRect = QRectF( pos().x(), pos().y(), size.width(), size.height() );
111-
attemptSetSceneRect( targetRect );
111+
QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( size, sizeWithUnits().units() );
112+
attemptResize( newSize );
112113
}
113114
else if ( size.height() > rect().height() || size.width() > rect().width() )
114115
{
115116
//need to resize box
116-
QRectF targetRect = QRectF( pos().x(), pos().y(), rect().width(), rect().height() );
117-
if ( size.height() > targetRect.height() )
118-
targetRect.setHeight( size.height() );
119-
if ( size.width() > rect().width() )
120-
targetRect.setWidth( size.width() );
117+
QSizeF targetSize = rect().size();
118+
if ( size.height() > targetSize.height() )
119+
targetSize.setHeight( size.height() );
120+
if ( size.width() > targetSize.width() )
121+
targetSize.setWidth( size.width() );
121122

123+
QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( targetSize, sizeWithUnits().units() );
122124
//set new rect, respecting position mode and data defined size/position
123-
attemptSetSceneRect( targetRect );
125+
attemptResize( newSize );
124126
}
125127
}
126128
QgsLayoutItem::paint( painter, itemStyle, pWidget );

0 commit comments

Comments
 (0)