开发者

How to determine the number of charecter will fit to screen in Qt

开发者 https://www.devze.com 2023-01-03 06:52 出处:网络
How do I determine the number of characters in a particular font will fit to the 开发者_JAVA技巧screen?Have a look at QFontMetrics. Using this, you can determine, among other things, the width of a pa

How do I determine the number of characters in a particular font will fit to the 开发者_JAVA技巧screen?


Have a look at QFontMetrics. Using this, you can determine, among other things, the width of a particular string:

QFontMetrics metrics(myFont);
int width = metrics.width(myString);

Is this what you want?

Note: It is not possible to find the number of characters of a particular font that will fit on the screen since not all fonts are monospace. So the number of characters will depend on the actual characters.


you can also use QFontMetrics::elidedText passing available space (remember to reduce it with margins/paddings. Then call length on result string

0

精彩评论

暂无评论...
验证码 换一张
取 消