PDA

View Full Version : problem in drawText



wagmare
29th July 2009, 13:26
hi friends,

i got a problem in QPainter::drawText()
i try to insert a new line "\n" to a QString text "Maintenance" as

string = "main \ntenance";

but it displayed as main[]tenance .. a box like undefined char is showing instead of
"main
tenance"

so i tried

string.insert(4, "\n"); //same as previous
string.insert(4, QChar::LineSeparator); //same as previous

this one is working fine if i use QGraphicsTextItem

please help me solving this issue ..

yogeshgokul
29th July 2009, 13:36
This function does not handle the newline character (\n), as it cannot break text into multiple lines, and it cannot display the newline character. Use the QPainter::drawText() overload that takes a rectangle instead if you want to draw multiple lines of text with the newline character, or if you want the text to be wrapped.

wagmare
29th July 2009, 13:42
Use the QPainter::drawText() overload that takes a rectangle instead if you want to draw multiple lines of text with the newline character, or if you want the text to be wrapped.

can't get it .. how to wrap the text .. ?

yogeshgokul
29th July 2009, 13:50
can't get it .. how to wrap the text .. ?
Buddy this is damm easy. Use:


void QPainter::drawText ( const QRectF & rectangle, int flags, const QString & text, QRectF * boundingRect = 0 )

And use this property in argument flags.


Qt::TextWordWrap
;)

wagmare
29th July 2009, 13:52
thank you very much gokul