[Interest] Pixmap redraw on OS X Retina display zoomed-in 4x?

Edward Sutton edward.sutton at subsite.com
Fri Jan 22 23:34:21 CET 2016


This seemed to solve my problem:


https://bugreports.qt.io/browse/QTBUG-46846

QLabel scaledContents broken on high resolution (retina) displays



    // https://bugreports.qt.io/browse/QTBUG-46846

    QImage scaledImage = pixmap.toImage().scaled(pixmap.size() * devicePixelRatio(),

                                                 Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

    scaledImage.setDevicePixelRatio(devicePixelRatio());

    QPixmap* newScaledPixmap = new QPixmap(QPixmap::fromImage(scaledImage));

    QLabel *labelButtonIcon = new QLabel();

    labelButtonIcon->setPixmap(*newScaledPixmap);

0Ed


On Jan 22, 2016, at 3:24 PM, Edward Sutton <edward.sutton at subsite.com<mailto:edward.sutton at subsite.com>> wrote:


On Jan 22, 2016, at 2:38 PM, Till Oliver Knoll <till.oliver.knoll at gmail.com<mailto:till.oliver.knoll at gmail.com>> wrote:



Am 22.01.2016 um 20:44 schrieb Edward Sutton <edward.sutton at subsite.com<mailto:edward.sutton at subsite.com>>:


On Jan 22, 2016, at 1:30 PM, Jason H <jhihn at gmx.com<mailto:jhihn at gmx.com>> wrote:

>Look for something called DevicePixelRatio... Also QML Screen attached property/element. It might be a shortcoming in Qt, but you should be able to work around it.

Thanks Jason.  I have same issue on iOS as well.

I will Google Qt examples for DevicePixelRatio. I am puzzled why Qt scaling does not occur automatically?

Maybe it does automatically scale for QML.  I am using QWidgets.

>Just a shot into the blue: at least on OS X have to be made "Retina ready" by setting some property in the Info.plist file, something like "NSHighResolutionCapable" (true). Plus the "principal class" (?) has to be set there as well, as a precondition.

I have NSHighResolutionCapable in my OS X list but not my iOS.


>Off course /not/ setting those values should not result in "4x magnified images" on a retina screen. Sounds like Qt thinks it needs to draw the @2x image resources, whereas OS X treats the application as "non-retina capableā€.


It may be a problem with myself.

I feel like I have too many size-things and do not know which one I should be compensating for and which one to adjust.

In an attempt to avoid creation of multiple icons of various size, I am using SVG icons from Google Material and QSvgRenderer to paint to a QPixmap.  Before



    QCommandLinkButton *buttonEditRow = new QCommandLinkButton(this);

    buttonEditRow->setIconSize(QSize(0,0));  // <- Hide green-arrow icon


    QLabel *labelRowNumber = new QLabel(rowNumber);

    QLabel *labelButtonText = new QLabel(displayName);


    // OSX HD.....:     devicePixelRatio = 1

    // OSX retina.:     devicePixelRatio = 2

    // iOS iPhone 5C:   devicePixelRatio = 2

    qDebug("devicePixelRatio: %i", this->devicePixelRatio());


    // too many size-things, what to fix and what to adjust?

    QString svgResource = ":/resource/images/edit_location.svg";

    QSvgRenderer svgRenderer(svgResource);

    QPixmap pixmap(svgRenderer.defaultSize());

    pixmap.fill(Qt::transparent);

    QPainter pixPainter(&pixmap);

    svgRenderer.render(&pixPainter);


    QLabel *labelButtonIcon = new QLabel();

    QSize sizeMaximum(32, 32);

    labelButtonIcon->setMaximumSize(sizeMaximum);

    labelButtonIcon->setScaledContents(true);

    labelButtonIcon->setPixmap(pixmap);


    QHBoxLayout *pLayout = new QHBoxLayout(buttonEditRow);

    pLayout->addWidget(labelRowNumber);

    pLayout->addWidget(labelButtonIcon);

    pLayout->addWidget(labelButtonText);

    pLayout->setAlignment(Qt::AlignLeft);

    pLayout->setContentsMargins(4,0,0,0);

    buttonEditRow->setLayout(pLayout);




>What about plain text (in widgets)? Does it look "retina-like"? Or pixelated (which would indicate that the OS treats the app as "non-retina capable") on the retina screen?

I think QLabel text displays crisper on the retina side. I have OS X 10.10.5.  The same 4x icon problem on iOS displays 1/4 of the pixmap.


>Maybe just some hope: my own QWidget/QGraphicsView based app looks fine, including QGraphicItems in the QGraphicView. Latest Qt 5.5.1 stock binary, El Capitan.
>Even moving the app between retina/non-retina screens works as expected: the Qt app redraws itself with the appropriate resolution as soon as more than 50% of the window overlap with the "other" screen.

My QGraphicsView of a graph also displays fine on both HD and retina.

Also other QIcon based PNG images loaded into buttons display fine as well.

Even when I load this same SVG image into a QComboBox item using QIcon ( no need for to use QSvgRenderer with QIcon ) it also renders fine on retina display.

It must be something to do with SVG rendering to QPixmap that is put into a QLabel. Too many size-things

-Ed


Cheers,
  Oliver
_______________________________________________
Interest mailing list
Interest at qt-project.org<mailto:Interest at qt-project.org>
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.qt-2Dproject.org_mailman_listinfo_interest&d=CwICAg&c=G4BpsyPyB19LB50bn2swXw&r=cAG2c-SQES5P2qb8IW-uwnBOCX_f2qYJIlzenFnoHUc&m=D97X0Ku9SZ1rD2DxirFw1q4nax2QDw6XA8KfqNs7iSs&s=EpJ4I4CYXxv4DogbqzwSNm-MsaITbJ4aY2rHDqHBsCU&e=

This email and any files transmitted with it from The Charles Machine Works, Inc. are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the sender. Our company accepts no liability for the contents of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email._______________________________________________
Interest mailing list
Interest at qt-project.org<mailto:Interest at qt-project.org>
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.qt-2Dproject.org_mailman_listinfo_interest&d=CwICAg&c=G4BpsyPyB19LB50bn2swXw&r=cAG2c-SQES5P2qb8IW-uwnBOCX_f2qYJIlzenFnoHUc&m=COj4lU8nx5MQM4ggLNYX_skxi-ZdsTui9PEtWK5hW5Y&s=Ubid9_sx6sdwKSZ0B019qgRuaTw3m56k-lQcQ3tJGL0&e=

This email and any files transmitted with it from The Charles Machine Works, Inc. are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the sender. Our company accepts no liability for the contents of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160122/ced20379/attachment.html>


More information about the Interest mailing list