August 1, 2011

dxwang dxwang
Lab Rat
20 posts

how to vertical the text and control the line spacing by QPainter::drawText(rect,text)

 

I have tried to add ‘\n’ to each character, but I find line spacing is too large, how I can control this line spacing.
painter->drawText (position,“Qt by \n Trolltech”);

thanks

6 replies

August 1, 2011

Gerolf Gerolf
Robot Herder
3253 posts

You can try to modify the different parameters of a QFont.

  1. MyWidget::paintEvent(...)
  2. {
  3.     QPainter p(this);
  4.     QFont ft = font();
  5.     ft.xxx();
  6.     p.setFont(ft);
  7. }

But I’m not 100% sure, whether you can change line height…

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

August 1, 2011

dxwang dxwang
Lab Rat
20 posts

thanks Gerolf. the font size is 16, it can be changed by user. it means that the text size is ok, just the line spacing is too large,because of “\n”. but how to reset line spacing.

August 1, 2011

Gerolf Gerolf
Robot Herder
3253 posts

I meant the line height of the font, which is typically ascent + descent + leading (look at QFontMetrics) and which is located in the font properties.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

August 1, 2011

dxwang dxwang
Lab Rat
20 posts

ok, I see.

August 1, 2011

dxwang dxwang
Lab Rat
20 posts

I am sorry, I still don’t find that which function can set line spacing in QFont. can someone help me .

January 24, 2012

pratik041 pratik041
Lab Rat
346 posts
dxwang wrote:
I am sorry, I still don’t find that which function can set line spacing in QFont. can someone help me .

Did you find the answer. I am searching something similar ?

 Signature 

Pratik Agrawal

 
  ‹‹ [SOLVED] Problems using debugger - “Cannot continue debugged process”      Voice Application! ››

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