You could also do something like this...
QFont serifont
( "Times" );
qreal size1_x, size2_x, size1_y, size2_y;
QMatrix xform
= painter.
combinedMatrix();
QMatrix invertedxform
= xform.
inverted();
// calculate and set pixel height for font to be 3% of the display area size
invertedxform.map( qreal( width() * 0.10 ), qreal( height() * 0.10 ), &size1_x, &size1_y );
invertedxform.map( qreal( width() * 0.13 ), qreal( height() * 0.13 ), &size2_x, &size2_y );
serifFont.setPixelSize( static_cast< int >( qAbs( size2_x - size1_x ) ) );
painter.setFont( serifFont );
QFont serifont( "Times" );
qreal size1_x, size2_x, size1_y, size2_y;
QMatrix xform = painter.combinedMatrix();
QMatrix invertedxform = xform.inverted();
// calculate and set pixel height for font to be 3% of the display area size
invertedxform.map( qreal( width() * 0.10 ), qreal( height() * 0.10 ), &size1_x, &size1_y );
invertedxform.map( qreal( width() * 0.13 ), qreal( height() * 0.13 ), &size2_x, &size2_y );
serifFont.setPixelSize( static_cast< int >( qAbs( size2_x - size1_x ) ) );
painter.setFont( serifFont );
To copy to clipboard, switch view to plain text mode
This will ensure that the font size will stay the same if you scale the coordinates of the widget. I'm sure there's a more elegant way to accomplish it though.
Bookmarks