@@ -106,21 +106,23 @@ void QgsLayoutItemLegend::paint( QPainter *painter, const QStyleOptionGraphicsIt
106
106
if ( mForceResize )
107
107
{
108
108
mForceResize = false ;
109
+
109
110
// 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 );
112
113
}
113
114
else if ( size.height () > rect ().height () || size.width () > rect ().width () )
114
115
{
115
116
// 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 () );
121
122
123
+ QgsLayoutSize newSize = mLayout ->convertFromLayoutUnits ( targetSize, sizeWithUnits ().units () );
122
124
// set new rect, respecting position mode and data defined size/position
123
- attemptSetSceneRect ( targetRect );
125
+ attemptResize ( newSize );
124
126
}
125
127
}
126
128
QgsLayoutItem::paint ( painter, itemStyle, pWidget );
0 commit comments