02-21-2012 12:19 PM
Please help me understand irregularity in character width.
This code:
QFontMetrics fm(font());
double x=fm.width("A");
qDebug()<< "Width of A is " << x;
x=fm.width("AA");
qDebug()<< "Width of AA is " << x;
x=fm.width("AAA");
qDebug()<< "Width of AAA is " << x;
x=fm.width("AAAA");
qDebug()<< "Width of AAAA is " << x;
produces these results:
Width of A is 11
Width of AA is 23
Width of AAA is 34
Width of AAAA is 46
Thanks.
Solved! Go to Solution.
02-21-2012 12:24 PM
02-21-2012 12:28 PM
02-21-2012 12:33 PM
02-21-2012 01:45 PM - edited 02-21-2012 01:52 PM
>>Does anybody know a font that does not do this nasty thing (glyphs are 11 or 12)?
probably, you need to try to use monospace font, like Courier/ Sans mono etc (this kind of fonts normaly use fixed integer width)
Dejavu Sans Mono & Bitstream Vera Sans Mono looks like can used
02-21-2012 01:51 PM
This is all fonts available for Playbook:
"Andale Mono"
"Arial"
"Bengali OTS"
"Comic Sans MS"
"Courier New"
"Devanagari OTS"
"Georgia"
"Gujarati OTS"
"Gurmukhi OTS"
"Impact"
"Kannada OTS"
"Malayalam OTS"
"Tahoma"
"Tamil OTS"
"Telugu OTS"
"Times New Roman"
"Trebuchet MS"
"Verdana"
"Webdings"
"Wingdings"
"Wingdings 2"
"Wingdings 3"
Still not sure where fonts set is coming from.. -(
02-21-2012 01:55 PM - edited 02-21-2012 01:56 PM
"Andale Mono" & "Courier New" can be a candidates from your list.
but I can see, that Dejavu Sans Mono & Bitstream Vera Sans Mono also installed on PB
02-21-2012 02:02 PM - edited 02-21-2012 02:08 PM
and you can try to use QFont::Monospace or QFont::Courier/QFont::TypeWriter
upd: QFont::ForceIntegerMetrics 0x0400 forces the use of integer values in font engines that support fractional font metrics. - this can be a choice with your current font
upd2: enum QFont:
tyleStrategy can also affect (smile is wrong - it's QFont :: StyleStrategy w/o spaces)
02-21-2012 02:17 PM
setStyleStrategy(QFont::ForceIntegerMetrics);
worked!
Width of A is 11
Width of AA is 22
Width of AAA is 33
Width of AAAA is 44
Thanks Andrey.