Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Font bearing and Qt::TextWordWrap
fsilva last edited by
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 ([url=http://stackoverflow.com/questions/23737591/qpainter-drawtext-italic-writes-outside-of-the-rectangle]post here[/url]) 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.