mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Add converter for dpi to pixel font size
Add a little function used to convert if needed the size of a font set in dpi to pixel. Because the conversion from pdi to pixel can't be exactly identical, the text size in the diagram can be a little different, in the other side the switch between screens with different dpi is no more a problem.
This commit is contained in:
parent
4ca0bbf682
commit
ae5e188866
@ -132,3 +132,21 @@ bool QETUtils::sortBeginIntString(const QString &str_a, const QString &str_b)
|
||||
return str_a<str_b;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QETUtils::pixelSizedFont
|
||||
* Set the font size to pixelSize instead of pointSize (if needed).
|
||||
* The font used to draw diagram must be pixel sized instead of point sized (default by Qt)
|
||||
* then no matter the screen dpi used, the text in diagram keep the same size.
|
||||
* For more information see @link https://qelectrotech.org/forum/viewtopic.php?pid=6267#p6267 @endlink
|
||||
* @param font
|
||||
*/
|
||||
void QETUtils::pixelSizedFont(QFont &font)
|
||||
{
|
||||
if (font.pixelSize() > -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto px = font.pointSizeF()/72 * QFontMetrics{font}.fontDpi();
|
||||
font.setPixelSize(qRound(px));
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ namespace QETUtils
|
||||
QString marginsToString(const QMargins &margins);
|
||||
QMargins marginsFromString(const QString &string);
|
||||
qreal graphicsHandlerSize(QGraphicsItem *item);
|
||||
void pixelSizedFont (QFont &font);
|
||||
|
||||
bool sortBeginIntString(const QString &str_a, const QString &str_b);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user