Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
Accepted Solution

QT and Font width

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.

Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: QT and Font width

It's going up by 11 or 12 each time so I would assume it's doing something like snapping the characters to pixel boundaries but the individual glyphs are like 11.5 pixels wide (handwaving a bit).

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: QT and Font width

Too bad...
Does anybody know a font that does not do this nasty thing (glyphs are 11 or 12)?
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: QT and Font width

If it wasn't clear, I was just guessing.

But note also that I didn't actually mean the glyph itself had to be that width as it could also be just the target spacing. It wants to be spacing them 11.5 (per my theory ) but tweaks the position as it goes so each character is drawn aligned with the pixels. Still just a guess.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Contributor
azazello
Posts: 40
Registered: ‎01-15-2012
My Device: Playbook Tablet

Re: QT and Font width

[ Edited ]

>>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

/rgds
Andrey Yaromenok aka azazello
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: QT and Font width

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.. -(

Contributor
azazello
Posts: 40
Registered: ‎01-15-2012
My Device: Playbook Tablet

Re: QT and Font width

[ Edited ]

"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

/rgds
Andrey Yaromenok aka azazello
Contributor
azazello
Posts: 40
Registered: ‎01-15-2012
My Device: Playbook Tablet

Re: QT and Font width

[ Edited ]

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::smileyfrustrated:tyleStrategy  can also affect (smile is wrong - it's QFont :: StyleStrategy w/o spaces)

/rgds
Andrey Yaromenok aka azazello
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: QT and Font width

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.