Skip to content

Commit b7902ca

Browse files
author
mhugent
committed
Fix for multiline labels in composer (ticket #181)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9202 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 2d4de7b commit b7902ca

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/core/composer/qgscomposerlabel.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
4848
painter->setFont( mFont );
4949

5050
QFontMetricsF fontSize( mFont );
51-
painter->drawText( QPointF( mMargin, mMargin + fontSize.ascent() ), mText );
51+
52+
//support multiline labels
53+
double penWidth = pen().widthF();
54+
QRectF painterRect(penWidth, penWidth, rect().width() - 2 * penWidth, \
55+
rect().height() - 2 * penWidth);
56+
painter->drawText(painterRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, mText);
57+
5258

5359
drawFrame( painter );
5460
if ( isSelected() )
@@ -60,7 +66,6 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
6066
void QgsComposerLabel::setText( const QString& text )
6167
{
6268
mText = text;
63-
adjustSizeToText();
6469
}
6570

6671
void QgsComposerLabel::setFont( const QFont& f )
@@ -76,13 +81,12 @@ void QgsComposerLabel::setFont( const QFont& f )
7681
{
7782
mFont = f;
7883
}
79-
adjustSizeToText();
8084
}
8185

8286
void QgsComposerLabel::adjustSizeToText()
8387
{
8488
QFontMetricsF fontInfo( mFont );
85-
setSceneRect( QRectF( transform().dx(), transform().dy(), fontInfo.width( mText ) + 2 * mMargin, fontInfo.ascent() + 2 * mMargin ) );
89+
setSceneRect( QRectF( transform().dx(), transform().dy(), fontInfo.width( mText ) + 2 * mMargin + 2 * pen().widthF(), fontInfo.ascent() + 2 * mMargin + 2 * pen().widthF()) );
8690
}
8791

8892
QFont QgsComposerLabel::font() const

0 commit comments

Comments
 (0)