void QgsLayoutItemLabel::adjustSizeToText() { QSizeF newSize = sizeForText(); //keep alignment point constant double xShift = 0; double yShift = 0; itemShiftAdjustSize( newSize.width(), newSize.height(), xShift, yShift ); //update rect for data defined size and position attemptSetSceneRect( QRectF( pos().x() + xShift, pos().y() + yShift, newSize.width(), newSize.height() ) ); }
void QgsComposerLabel::adjustSizeToText() { double textWidth = QgsComposerUtils::textWidthMM( mFont, displayText() ); double fontHeight = QgsComposerUtils::fontHeightMM( mFont ); double penWidth = hasFrame() ? ( pen().widthF() / 2.0 ) : 0; double width = textWidth + 2 * mMarginX + 2 * penWidth + 1; double height = fontHeight + 2 * mMarginY + 2 * penWidth; //keep alignment point constant double xShift = 0; double yShift = 0; itemShiftAdjustSize( width, height, xShift, yShift ); //update rect for data defined size and position QRectF evaluatedRect = evalItemRect( QRectF( pos().x() + xShift, pos().y() + yShift, width, height ) ); setSceneRect( evaluatedRect ); }