Nominate our 2022 Qt Champions!

Text improperly scaled in QLineEdit wrapped in a QGraphicsProxyWidget when QGraphicsView is scaled

    1. Create a QLineEdit.
    2. Put it in a QGraphicsProxyWidget and include the proxy in a QGraphicsScene, or just call addWidget from the QGraphicsScene instance.
    3. Create a QGraphicsView and set its scene to be the scene you have just created.
    4. Now scale the view using: QGraphicsView::setScale(qreal sx, qreal sy).
    5. 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:

  • Found a workaround:

    1. 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.
    2. Detect the view scaling.
    3. 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 ).
    4. Scale down the proxy widget by 1.0 / scale.

Log in to reply