April 4, 2012

Jupiter Jupiter
Lab Rat
95 posts

How to set correct PointSize in a QGraphicsTextItem

 

Hi,

I want to have a QGraphicsTextItem with the correct point size (1pt = 0.3527mm). however 1 unit in my scene is 1 mm.
i tried to call setPointSizeF() with the correct calculated size, but somehow only the pointsize() is called for drawing the text. So only about every third pt the actual font size is changed (3*0.3527 ~ 1.0). How can i change this?

Thanks

1 reply

April 4, 2012

sraboisson sraboisson
Lab Rat
8 posts

Perhaps your falling in the documentation remark of “setPointSizeF”:
“… The requested precision may not be achieved on all platforms”
Did you try using “setPixelSize” (calculating the pixel size corresponding to the desired font height) ?
Something like

  1.     float lPixelSizeInMillimeters = 0.3527;
  2.     float lFontSizeInMillimeters = 12.4:
  3.     int   lFontSizeInPixels;
  4.  
  5.     lFontSizeInPixels = (int)(lFontSizeInMillimeters / lPixelSizeInMillimeters)
  6.     m_textFont.setPixelSize(lFontSizeInPixels);

Hope this is possible and will help…

 
  ‹‹ How to change the repaint order of layered QWidget in Qt?      QPainter and OpenGL (Pixel- or Framebuffer) ››

You must log in to post a reply. Not a member yet? Register here!