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

Transparent QPainter::drawPixmap with QPainter::setCompositionMode does not work correctly on macOS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.4.2
    • GUI: Painting
    • None
    • macOS

    Description

      Drawing a transparent QPixmap on macOS with composition mode does not work as expected. It draws the transparent areas of the pixmap with the window background colour (light grey or dark grey, depending upon whether the OS is in light or dark mode), and this happens even when it is not drawing directly to a QWidget (e.g. in a QItemDelegate). The same operation works as expected on at least Win32 and X11.

      The attached test case demonstrates a minimal reproduction of the issue. Screenshots of actual results on each platform are also attached.

      The only way I have found to render a QPixmap to a widget on macOS with correct composition is to make a new temporary QPixmap, fill it with Qt::transparent, draw into the temporary using the intended composition mode, then draw the temporary into the intended destination using no composition mode.

      I tried searching the documentation to see if there are any macOS-specific flags that need to be set to avoid this problem (didn’t see any), and also searched the bug tracker for related issues (there are some, but they seem to be ancient or closed, and some of the workarounds given don’t appear to work any more).

      Attachments

        1. test.png
          test.png
          0.5 kB
        2. qt-qpainter-test.tar.gz
          2 kB
        3. image-2023-03-15-11-07-56-549.png
          image-2023-03-15-11-07-56-549.png
          0.5 kB
        4. image-2023-03-15-11-06-35-948.png
          image-2023-03-15-11-06-35-948.png
          3 kB
        5. image-2023-03-15-11-06-28-215.png
          image-2023-03-15-11-06-28-215.png
          2 kB
        6. image-2023-03-15-11-06-16-286.png
          image-2023-03-15-11-06-16-286.png
          0.5 kB
        7. actual-x11.png
          actual-x11.png
          2 kB
        8. actual-win32.png
          actual-win32.png
          2 kB
        9. actual-macos.png
          actual-macos.png
          4 kB
        10. 1.png
          1.png
          2 kB

        Activity

          People

            vgt Eirik Aavitsland
            csnover C S
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: