Details
-
Bug
-
Resolution: Incomplete
-
P4: Low
-
4.7.1
-
None
-
Windows Vista/7
Description
Note the following two ways of creating a metrics QFontMetrics object:
- QFontMetrics fm(QFont(), 0) creates a metrics object which is screen-compatible.
- QFontMetrics fm(QFont()), creates a metrics object which is compatible with the paintdevice used to create the font.
I would expect that if there was no paintdevice used when creating the font, the two metrics objects created by the two different constructors should be the same. This means that I would expect both metrics objects to be screen-compatible. In some cases though, the second constructor constructs an object compatible with some "default" paintdevice having 96 DPI, instead of the 144 DPI for the metrics object created by the first constructor.
Example application:
#include <QtGui>
int main( int argc, char * argv[] )
{
QApplication A(argc, argv);
QFont font1("Helvetica", 10);
QFont font2; font2.setFamily("Helvetica");
font2.setPointSize(10);
QFont font3(font1, &QPixmap(1,1));
QFont font4(font2, &QPixmap(1,1));
int acw1 = QFontMetrics(font1).averageCharWidth();
int acw2 = QFontMetrics(font1, 0).averageCharWidth();
int acw3 = QFontMetrics(font2).averageCharWidth();
int acw4 = QFontMetrics(font2, 0).averageCharWidth();
int acw5 = QFontMetrics(font3).averageCharWidth();
int acw6 = QFontMetrics(font4).averageCharWidth();
QMessageBox msgBox;
msgBox.setText( QString::number(acw1) + " " + QString::number(acw2) + " " + QString::number(acw3) + " " + QString::number(acw4) + " " + QString::number(acw5) + " " + QString::number(acw6));
msgBox.exec();
return 0;
}
This example application gives the result: "9 9 6 9 9 9" with 150% scaled fonts. Expected result: "9 9 9 9 9 9"
Appendix: To reproduce on Windows Vista and Windows 7, one can adjust the DPI and use emulated scaling. This is set up in the following way (Windows Vista):
->Control Panel
->Personalization
->Adjust Font Size (DPI)
->Custom DPI...
->Set the percentage to for example 150%
->Turn OFF checkbox "Use Windows XP style DPI scaling"