How to get the QRect size of MultiLine QString text that need display in multiple line?
-
I have a long QString text need to display in multiple-line,so I use QFontMetrics::boundingRect to calculate the QRect size ,because my text is long so that I used Qt::TextWordWrap ,but the rect size returned is only the single-line,so what is the wrong ?My code is underline.Thanks!
QPainter painter(this); QString text("1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890"); int width = this->width()-40; int flags = Qt::TextWordWrap; qDebug()<<"font:"<<painter.font().pointSize()<<",pixelSize="<<painter.font().pixelSize(); QFontMetrics metrics = painter.fontMetrics(); QRect textBoundingRect = metrics.boundingRect(QRect(0,0,width,0),flags,text); painter.translate(20,20); painter.drawRect(textBoundingRect); painter.drawText(textBoundingRect,Qt::TextWordWrap,text);
-
I have a long QString text need to display in multiple-line,so I use QFontMetrics::boundingRect to calculate the QRect size ,because my text is long so that I used Qt::TextWordWrap ,but the rect size returned is only the single-line,so what is the wrong ?My code is underline.Thanks!
QPainter painter(this); QString text("1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890" "1234567890123456789012345678901234567890"); int width = this->width()-40; int flags = Qt::TextWordWrap; qDebug()<<"font:"<<painter.font().pointSize()<<",pixelSize="<<painter.font().pixelSize(); QFontMetrics metrics = painter.fontMetrics(); QRect textBoundingRect = metrics.boundingRect(QRect(0,0,width,0),flags,text); painter.translate(20,20); painter.drawRect(textBoundingRect); painter.drawText(textBoundingRect,Qt::TextWordWrap,text);