这段代码:
QFont convertPointToPixelSize( const QFont& f )
{
QFont ret( f );
QFontInfo fi( ret );
ret.setPixelSize( fi.pixelSize() );
return ret;
}
qDebug() << "getFont()=" << getFont();
qDebug() << "convertPointToPixelSize( getFont() )=" << convertPointToPixelSize( getFont());
在 Qt 4.8.5 上返回:
getFont()= QFont( "MS Shell Dlg 2,36,-1,5,50,0,0,0,0,0" )
convertPointToPixelSize( getFont() )= QFont( "MS Shell Dlg 2,-1,48,5,50,0,0,0,0,0" )
getFont()= QFont( "Arial,28,-1,5,50,0,0,0,0,0" )
convertPointToPixelSize( getFont() )= QFont( "Arial,-1,37,5,50,0,0,0,0,0" )
getFont()= QFont( "Times New Roman,72,-1,5,50,0,0,0,0,0" )
convertPointToPixelSize( getFont() )= QFont( "Times New Roman,-1,96,5,50,0,0,0,0,0" )
这在 Qt 5.11.1 上:
getFont()= QFont( "MS Shell Dlg 2,36,-1,5,50,0,0,0,0,0" )
convertPointToPixelSize( getFont() )= QFont( "MS Shell Dlg 2,-1,72,5,50,0,0,0,0,0" )
getFont()= QFont( "Arial,28,-1,5,50,0,0,0,0,0" )
convertPointToPixelSize( getFont() )= QFont( "Arial,-1,56,5,50,0,0,0,0,0" )
getFont()= QFont( "Times New Roman,72,-1,5,50,0,0,0,0,0" )
convertPointToPixelSize( getFont() )= QFont( "Times New Roman,-1,144,5,50,0,0,0,0,0" )
请注意为相同字体返回的不同 QFontInfo::pixelSize() 值。所以 QFontInfo::pixelSize() 似乎在 Qt 4 和 Qt 5 之间发生了变化(为 Qt 5 返回更大的值)。我能做些什么来获取 Qt 5 中 Qt 4 的 QFontInfo::pixelSize() 的值吗?我查看了 QFontMetrics,但没有看到任何有用的东西。