High DPI ("Retina") support in Qt 5.5 - handling multiple displays of different DPIs



  • I'm in the process of updating my app to support x2 resolution bitmaps for all of the app's graphics on Mac OS 10.10 with Qt 5.5. I've found that on systems with both a retina display and a non-retina display, the 2x graphics look pretty horrible on the non-retina display as they are scaled down.

    So instead of just setting which version of the image to use when a window is created based on if any display was high DPI, I'm trying to do it dynamically based on which screen the window is on.

    Before I could set the image to use in a QLabel from within my dialog's .ui file. However now I need to switch the image based on the display it's on, so I'm hard-coding all of the image names which isn't every elegant - especially when there are many different images in the dialog. For example I have:

    my_dialog::::update_retina_icons()
    {
        static int previous_devicePixelRatio;
        int new_devicePixelRatio=devicePixelRatio();
        if (previous_devicePixelRatio!=new_devicePixelRatio)
        {
        previous_devicePixelRatio=new_devicePixelRatio;
        if (new_devicePixelRatio > 1.0)
            label->setPixmap(QPixmap(":/images/Resources/abc@2x.png")); 
        else
            label->setPixmap(QPixmap(":/images/Resources/abc.png")); 
        }
    }
    

    Does anyone have a better suggestion on how to do this so I'm not basically duplicating setting QLabel graphics from within my code from those that were set from the original .ui file?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.