Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Retina (@2x) icons are not being loaded from resource (.qrc)
Forum Updated to NodeBB v4.3 + New Features

Retina (@2x) icons are not being loaded from resource (.qrc)

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 7.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cperezabo
    wrote on last edited by
    #1

    Hi, I have placed both the standard icon (app.png) and the retina one (app@2x.png) into a resource (.qrc).
    In designer I've chosen the app.png one, but it is not being changed automatically in retina display systems as expected.
    It have been working whereas I used images from folders, but now that I am trying to make my app more "portable" it stop working!.

    Any Idea??

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      My guess is that the automagic @2x kludge implemented by Apple is done when the OS X API functions (perhaps NSImage) see a matching "@2x" file in the same place as the file you actually asked for. Since the Qt resources are handled internally these virtual file accesses are not passed off to the OS X API which, understandably, cannot perform the magic of returning something other than what you asked for.

      1 Reply Last reply
      0
      • GianlucaG Offline
        GianlucaG Offline
        Gianluca
        wrote on last edited by
        #3

        For using the "@2x" images with Qt I use a trick described in this topic:
        http://qt-project.org/forums/viewthread/44805/

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cperezabo
          wrote on last edited by
          #4

          It seems to be "automagic" isn't implemented on QPixmap.
          As you can see in the source code:
          https://github.com/Vitallium/qt5/blob/master/qtbase/src/gui/image/qicon.cpp
          QIcon makes the "automagic" for @2x files in the QIcon::addFile method, but QPixmap doesn't.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cperezabo
            wrote on last edited by
            #5

            Well, I just did the same fix and overrided the involved methods
            It works at expected. My program is written in python. So I share the code in that language, but it can help someone else!.
            @
            def at2x_fix(fileName):
            if qApp.devicePixelRatio() >= 2:
            subfile, fext = os.path.splitext(fileName)
            fileRetina = subfile + "@2x" + fext

                if QFile(fileRetina).exists():
                    return fileRetina
            return fileName
            

            def QPixmap_init(self, fileName, *args, **kwargs):
            fileName = at2x_fix(fileName)
            QPixmap_init_old(self, fileName, *args, **kwargs)
            QPixmap_init_old = QtGui.QPixmap.init
            QtGui.QPixmap.init = QPixmap_init

            def QPixmap_load(self, fileName, *args, **kwargs):
            fileName = at2x_fix(fileName)
            QPixmap_load_old(self, fileName, *args, **kwargs)
            QPixmap_load_old = QtGui.QPixmap.load
            QtGui.QPixmap.load = QPixmap_load
            @

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved