Text improperly scaled in QLineEdit wrapped in a QGraphicsProxyWidget when QGraphicsView is scaled
-
- Create a QLineEdit.
- Put it in a QGraphicsProxyWidget and include the proxy in a QGraphicsScene, or just call addWidget from the QGraphicsScene instance.
- Create a QGraphicsView and set its scene to be the scene you have just created.
- Now scale the view using: QGraphicsView::setScale(qreal sx, qreal sy).
- Notice that on Windows and Linux the text looks good, but on Mac OS X it is displayed pixelated.
Windows and Linux:
text: scaled (rasterized at actual resolution)
QLineEdit's border: magnified (pixelated)Mac OS X:
text: magnified (pixelated)
QLineEdit's border: magnified (pixelated)A sample project is attached to the following bugreport:
https://bugreports.qt.nokia.com/browse/QTBUG-21783 -
Found a workaround:
- Set the QLineEdit's font to have pixel size equivalent to the height of the QLineEdit widget. Do this in the showEvent function of the class that wraps the QGraphicsView, QGraphicsProxyWidget and QLineEdit or in the showEvent function of a QLineEdit subclass. Save this pixel size to a member variable.
- Detect the view scaling.
- In the detection function set the pixel size of the QLineEdit's font to be equal to the cached font pixel size ( point 1) ) multiplied by the uniform view scale ( make the view scale uniform ).
- Scale down the proxy widget by 1.0 / scale.