QFont::fromString() change between Qt 4 and Qt 5
-
The differences are significant. For example look at the big text which is Arial Italic 72, on Qt 4 versions of my app:
And Arial Italic 72, on Qt 5 versions of my app:
It isn't a showstopper though. Users will just have to modify the fonts if they move a plan from PerfectTablePlan v5 to PerfectTablePlan v6. Just wanted to make sure I wasn't missing anything.
--
Andy Brice
https://www.perfecttableplan.com -
The differences are significant. For example look at the big text which is Arial Italic 72, on Qt 4 versions of my app:
And Arial Italic 72, on Qt 5 versions of my app:
It isn't a showstopper though. Users will just have to modify the fonts if they move a plan from PerfectTablePlan v5 to PerfectTablePlan v6. Just wanted to make sure I wasn't missing anything.
--
Andy Brice
https://www.perfecttableplan.com@AndyBrice
but this rather looks like the font size is different, than the weight.
regular/normal specifies the weight of a font, not it's size.Is this a QTextDocument (QTextEdit etc) you are using here?
-
It is a QPainter::drawText() inside a QGraphicsItem derived object drawn on a QGraphicsCanvas.
I believe it is the same font in both cases, but I will have a double check.
--
Andy Brice
https://www.perfecttableplan.com -
I am using pixel size, instead of point size. IIRC because I had issues with exporting point size fonts to PDF.
On Qt 5.11.1:
qDebug() << p->font();
returns:
QFont( "Arial,-1,144,5,50,1,0,0,0,0" )
On Qt 4.8.5:
qDebug() << p->font();
returns:
QFont( "Arial,-1,96,5,50,1,0,0,0,0" )
They are both reading in the same font generated by QFont::toString(). So I am not sure why the pixel sizes are different. I need to dig further.
--
Andy Brice
https://www.perfecttableplan.com -
I investigated a bit further. This code:
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());
Returns this on 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" )
And this on 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" )
So QFontInfo::pixelSize() seems to have changed between Qt 4 and Qt 5. It isn't a showstopper. But it is a minor annoyance.
--
Andy Brice
https://www.perfecttableplan.com -
I investigated a bit further. This code:
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());
Returns this on 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" )
And this on 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" )
So QFontInfo::pixelSize() seems to have changed between Qt 4 and Qt 5. It isn't a showstopper. But it is a minor annoyance.
--
Andy Brice
https://www.perfecttableplan.com@AndyBrice said in QFont::fromString() change between Qt 4 and Qt 5:
QFont convertPointToPixelSize( const QFont& f )
{
QFont ret( f );
QFontInfo fi( ret );
ret.setPixelSize( fi.pixelSize() );
return ret;
}what is the purpose of this method in the first place?
Do you want to set it's default pixel size? -
@AndyBrice said in QFont::fromString() change between Qt 4 and Qt 5:
QFont convertPointToPixelSize( const QFont& f )
{
QFont ret( f );
QFontInfo fi( ret );
ret.setPixelSize( fi.pixelSize() );
return ret;
}what is the purpose of this method in the first place?
Do you want to set it's default pixel size?@raven-worx IIRC it is because point font sizes don't work well when you export a QGraphicsCanvas to PDF. So I set pixel sizes (rather than point sizes) in the QGraphicsCanvas. To be honest, it is a bit lost in the mists of time and I am just trying to keep the Qt 5 version of my software backward compatible with the Qt 4 version.
--
Andy Brice
https://www.perfecttableplan.com -
@raven-worx IIRC it is because point font sizes don't work well when you export a QGraphicsCanvas to PDF. So I set pixel sizes (rather than point sizes) in the QGraphicsCanvas. To be honest, it is a bit lost in the mists of time and I am just trying to keep the Qt 5 version of my software backward compatible with the Qt 4 version.
--
Andy Brice
https://www.perfecttableplan.com@AndyBrice
ok then in this case a workaround could be simply to calculate the point to pixel conversation yourself:1 px = 0.75 pt
It may be that the newer (Qt5) implementation takes the current screen resolution into account, where the older (Qt4) didn't. -
@AndyBrice
ok then in this case a workaround could be simply to calculate the point to pixel conversation yourself:1 px = 0.75 pt
It may be that the newer (Qt5) implementation takes the current screen resolution into account, where the older (Qt4) didn't.@raven-worx Yes, it may be a related to the DPI of the device in Qt. I hadn't thought of that. In which case the ratio between pixels and points may vary between devices. I'll have to look through the QFontInfo::pixelSize() source. Thanks.
--
Andy Brice
https://www.perfecttableplan.com -
I have ended up multiplying the font point size by 0.66 when I read in plans created using Qt 4 on Windows. It is a bit of a hack, but it is good enough!
--
Andy Brice
https://www.perfecttableplan.com