PDA

View Full Version : Font bearing and Qt::TextWordWrap



fsilva
20th June 2014, 11:53
About a month ago I was having problems with QPainter.drawText writing outside of the bounds of the rectangle which I solved with the help of someone at Stackoverflow (post here (http://stackoverflow.com/questions/23737591/qpainter-drawtext-italic-writes-outside-of-the-rectangle)) which I solved using QFontMetrics::leftBearing and QFontMetrics::rightBearing.

As stated in the SO post I wanted to avoid having extra space to the left or to the right so I am only applying an offset to the left or to the right when the first or last character is problematic (has a negative bearing). Of course everything was fine until someone decided to add Qt::TextWordWrap into the mix. In this case any of the middle lines can span outside of the rectangle.

I would like to know if I am following the best approach in the first place and also if there is any way to determine where will QPainter insert line breaks when drawing with Qt::TextWordWrap.