Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-52152

Incorrect QIcon pixmap used for ItemView items

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.6.1, 5.12.0
    • None
    • Tested on Mac OSX 10.10, though I think the problem should exist on other platforms as well.
    • macOS

    Description

      Consider a situation in which you have a view with an item and you set the item's icon like this:

      setIcon(QIcon(":/icon.png"));
      

      If there happens to be a file in the same directory/resource location as icon.png that's named icon@2x.png, then the QIcon will load both of those resources so that the @2x version can be used on high DPI displays.

      If you're using a system on which you have two monitors, and one is a high DPI display and the other is standard DPI (eg. a retina iMac with an external monitor), then you would expect that if the window containing your view is on the high DPI display, the @2x version of the icon is used (icon@2x.png), and on the standard display the regular version is used (icon.png).

      Unfortunately, that's not what happens. Instead, the high resolution version is used regardless of which monitor the view is on. Depending on the icon, the @2x version that's downsampled may look pretty bad when displayed on the standard resolution monitor.

      This does not happen in some other cases in which QIcon is used. For example, on QToolButtons, the version of the icon appropriate for the device's devicePixelRatio is used.

      This is happening because of the following line of code in qcommonstyle.cpp (on/near line 2179)

      vopt->icon.paint(p, iconRect, vopt->decorationAlignment, mode, state);
      

      Instead, I believe that the QIcon::pixmap overload that takes a QWindow* parameter should be called, and then the pixmap should be painted using QPainter::drawPixmap.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sorvig Morten Sørvig
            aclight Adam Light
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes