Qt中获取文字的宽度和高度

QFontMetrics fm = painter->fontMetrics();
QPrinter *printer = new QPrinter;
mPixelPerCentimeter = printer->resolution()/2.54;
foreach(QString str,szTable)
{
	double tempWidth = fm.width(str)/mPixelPerCentimeter;
	width = qMax(tempWidth,width);
}					
double height = fm.height()/mPixelPerCentimeter*szTable.size();//mutiply line

你可能感兴趣的:(C++,c,C#,qt)