QFontMetric它一般用于文本宽高的处理。
QString text = "测试文本";
QFont font;
font.setPointSize(25);
QFontMetrics metrics(font);
int w = metrics.width(text);
int h = metrics.height(text);
多文本拼接自适应示例:
QRect leftrect = QRect(50,50,100,100);
p.drawText(leftrect,Qt::AlignCenter,"300.6");
p.drawText(QRect(leftrect.x() + metrics.width("300.6")+(leftrect.width()- metrics.width("300.6"))/2,50,20,20),Qt::AlignCenter,"V");