怎么获取一种特定字体的字符串的宽度
答案:2 悬赏:80
解决时间 2021-03-13 08:13
- 提问者网友:星空下的寂寞
- 2021-03-12 08:12
怎么获取一种特定字体的字符串的宽度
最佳答案
- 二级知识专家网友:狠傷凤凰
- 2021-03-12 09:23
Graphics graphics = CreateGraphics();
SizeF sizeF = graphics.MeasureString(textBox1.Text, new Font("宋体", 9));
MessageBox.Show(string.Format("字体宽度:{0},高度:{1}", sizeF.Width, sizeF.Height));
graphics.Dispose();
SizeF sizeF = graphics.MeasureString(textBox1.Text, new Font("宋体", 9));
MessageBox.Show(string.Format("字体宽度:{0},高度:{1}", sizeF.Width, sizeF.Height));
graphics.Dispose();
全部回答
- 1楼网友:滚刀废物浮浪人
- 2021-03-12 09:43
1. qlabel::fontmetrics().width(qstring s): 获取字符串s的总像素宽度。
int qfontmetrics::width ( const qstring & text, int len = -1 ) const
returns the width in pixels of the first len characters of text. if len is negative (the default), the entire string is used.
note that this value is not equal to boundingrect().width(); boundingrect() returns a rectangle describing the pixels this string will cover whereas width() returns the distance to where the next string should be drawn.
see also boundingrect().
2. qlabel::fontmetrics().height(): 获取字体的高度。
int qfontmetrics::height () const
returns the height of the font.
this is always equal to ascent()+descent()+1 (the 1 is for the base line).
see also leading() and linespacing().
3. qlabel::fontmetrics().linespacing(): 获取字体的高度,包括文字的实际宽度和行距。
4. qlabel::fontmetrics().leading(): 行间距
int qfontmetrics::leading () const
returns the leading of the font.
this is the natural inter-line spacing.
see also height() and linespacing().
其他函数参见qt 的 qfontmetrics class reference
int qfontmetrics::linespacing () const
returns the distance from one base line to the next.
this value is always equal to leading()+height().
see also height() and leading().
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯