PDA

View Full Version : how to make draw text word wrapped to fit the given font size plus rectangle



wagmare
3rd June 2014, 08:02
hi friends,

i am having a QGraphicsTextItem and QGraphicsItem where the user can give input text to the text item using setTextInteractionFlags.
now i wanted to draw the same text on the QGraphicsItem paint function .
so i passed the text item "text", "font" and the "boundingRect" to the QGraphicsItem paint event
TEXT = "theCurrentText"
FONT = "theCurrentFontSize"
boundingRect = m_bounds;

and painted as


QFont segoeFont("Segoe Regular");


segoeFont.setPointSizeF(theCurrentFontSize );
p->setFont(segoeFont);
p->setPen(actPen);
QFontMetricsF fma( p->font());

QRectF bounds = fma.boundingRect(QRectF(0, 0, m_bounds.width() , 0), Qt::TextWordWrap, theCurrentText);
p->fillRect(bounds, Qt::white);
p->drawText(bounds, Qt::TextWordWrap, theCurrentText);

but the text is not getting wrapped at any point . even hundreds of word i have given but still the words are getting cropped but showing in a single line.
my graphicstextitem
10389
and my graphicsitem
10390

i checked the debug statements of the the graphicstext item and graphicsitem .
The Ey Text item bounding rect value is: QRectF(-2,-2 1909.22x62)
The Ey text item font size value coming is: 8.25

The Ey Text bounding rect value is: QRectF(0,0 1909x86)
The Ey font size value coming is: 8.25

both bounding rect and font size are coming similar and both are child of same graphicsitem ..

please help me ..

wysota
3rd June 2014, 12:23
I would assume you are passing an incorrect rectangle to QFontMetrics::boundingRect().