PDA

View Full Version : Only integers from QFontMetricsF width



StevenB
10th November 2007, 00:25
I'm getting only integer values from QFontMetricsF::width() and QFontMetricsF.boundingRect().width().
I'm trying to use the width to draw a box with GraphicsView, but because of the integer coordinates, the box sometimes overlaps the text.

Here's the code I'm using:

QFont font("Sans", 12);
font.setPointSizeF(13.2524);
fontsizer = new QFontMetricsF(font);
std::cout << "width: " << fontsizer->width("string") << std::endl;
Am I doing something wrong?

jpn
10th November 2007, 10:01
Any particular reason why not to use readily available QGraphicsTextItem or QGraphicsSimpleTextItem?

StevenB
17th November 2007, 18:38
Any particular reason why not to use readily available QGraphicsTextItem or QGraphicsSimpleTextItem? I probably could use QGraphicsTextItem. However, I already have significant amount of code which uses QPainter::drawText inside a custom class derived from QGraphicsItem. I'd like to fix an integer-size related bug in this class without re-writing a lot of code.

StevenB
16th May 2008, 22:59
Sorry for reviving an old thread, but I'm still having problems with this. I'm doing a bunch of custom painting, and need to be able to line up my text. I'm running Qt 4.4 on Ubuntu Hardy.