PDA

View Full Version : how to get font width depending on its scale



iceman
28th July 2010, 07:50
Hello Friends,

i've tried to get font width depending on its scale.
for example, i wanna know how wider the font is in the scale 200 than 100.

Due to measure the font width depending on its scale, I wrote the sample test example.
-----------------------
QTransform oTransform;
oTransform.scale(1.2, 1.8);

QPainter oPainter;
oPainter.begin(this);
oPainter.setWorldMatrixEnabled(true);
oPainter.setWorldTransform(oTransform);

oPainter.drawText( x,y, g_strGreeting);
g_oFont.setWeight( weight );
oPainter.setFont( g_oFont );

QFontMetrics oFontMatrix(g_oFont);
int nStringSize = oFontMatrix.width(g_strGreeting);
--------------------------
But changing a font scale with QTransform can make the font drawn wider only, and then there's no change in the real width of the font which can be gotten by QFontMetrics::Width();

Is there another aproach to measure the changed font-width in proportion to its scale?
thanks.