中易网

怎么获取一种特定字体的字符串的宽度

答案:2  悬赏:80  
解决时间 2021-03-13 08:13
怎么获取一种特定字体的字符串的宽度
最佳答案
Graphics graphics = CreateGraphics();
SizeF sizeF = graphics.MeasureString(textBox1.Text, new Font("宋体", 9));
MessageBox.Show(string.Format("字体宽度:{0},高度:{1}", sizeF.Width, sizeF.Height));
graphics.Dispose();
全部回答
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().
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
兴涵电动车行我想知道这个在什么地方
现在社会到底有没有鬼。
青少年胡子很长能不能稍稍剪短些?,不是说全
3840095里面的8表示多少
跑步突然肾疼是怎么回事
健尔弹长沙马王堆内衣生活馆地址在哪,我要去
都说好人难当,的,歌名,叫什么
回复:我想玩WOW,是猎人好玩,还是德鲁伊好
上海易晟国际贸易有限公司怎么去啊,有知道地
两台电脑主板不同,一台能将另一台的硬盘装好
我手里有一套房子,不是按接的,我想再买一套二
本人想加盟互联网金融行业,想知道公司会提供
64平方米的卧室怎样
老公的姐姐在家生头胎我娘家亲戚要来送礼吗
麦点超市(进贤旗舰店)怎么去啊,有知道地址的
推荐资讯
蛋白质,脂肪,糖类和水的密度大小比较
羊山华庭怎么去啊,有知道地址的么
厨柜门怎么批发
和者日众是什么意思
求助,交流磁化率数据处理
touch炫舞中初始形象设置后能改不
香港大学有美术专业吗
记一件感人的事题目怎么起好
未成年可以去送达达外卖吗
坂田金色海岸,哪个技师漂亮手法可以,急求!
海清五谷养生这个地址在什么地方,我要处理点
安徽三清山有什么好玩的?
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?