Windows 7 SP1
MSVS 2010
Qt 4.8.4
我想确定 QLineEdit 小部件的最大大小,知道它必须容纳的最大字符数。
因此,我想使用:
int QFontMetrics::maxWidth () const
Returns the width of the widest character in the font.
但是这个:
#include <QApplication>
#include <QFont>
#include <QFontMetrics>
#include <iostream>
using std::cout; using std::endl;
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
QFontMetrics metrics(QApplication::font());
cout << "Default - Max width: " << metrics.maxWidth() << " Width of X: " << metrics.width('X') << endl;
const QFont f("Monospace", 8);
QFontMetrics metrics2(f);
cout << "Monospace 8 - Max width: " << metrics2.maxWidth() << " Width of X: " << metrics2.width('X') << endl;
const QFont f2("Cambria", 16);
QFontMetrics metrics3(f2);
cout << "Cambria 16 - Max width: " << metrics3.maxWidth() << " Width of X: " << metrics3.width('X') << endl;
return 0;
}
输出这个:
Default - Max width: 23 Width of X: 6
Monospace 8 - Max width: 23 Width of X: 6
Cambria 16 - Max width: 91 Width of X: 12
问题:为什么最大宽度比'X'的宽度大这么多?字体中是否有一些我不知道的超大字符?