Repository: matplotlib/matplotlib
File: lib/matplotlib/backends/backend_qt.py (Python)

Code before:
            painter.begin(pixmap)
            renderer.render(painter, QtCore.QRectF(0, 0, size.width(), size.height()))
        finally:
            if painter.isActive():
                painter.end()

        return pixmap

    def _render_png(self, png_path, pixmap, scaled_size, dpr):
        """Render PNG content to pixmap with scaling and dark mode support."""
        source_pixmap = QtGui.QPixmap(str(png_path))
        if source_pixmap.isNull():
            return QtGui.QPixmap()

        # Scale to requested size
        scaled_pixmap = source_pixmap.scaled(
            scaled_size,
            QtCore.Qt.AspectRatioMode.KeepAspectRatio,
            QtCore.Qt.TransformationMode.SmoothTransformation
        )
        scaled_pixmap.setDevicePixelRatio(dpr)

        # Apply dark mode adaptation if needed
        toolbar = self.toolbar
        if (toolbar and
                toolbar.palette().color(toolbar.backgroundRole()).value() < 128):
            # On some platforms (e.g., macOS with Qt5 in dark mode), this may
            # incorrectly return a black color instead of a light one.
            # See issue #27590 for details.
            icon_color = toolbar.palette().color(toolbar.foregroundRole())
            mask = scaled_pixmap.createMaskFromColor(
                QtGui.QColor('black'),
                QtCore.Qt.MaskMode.MaskOutColor)
            scaled_pixmap.fill(icon_color)
            scaled_pixmap.setMask(mask)

        return scaled_pixmap


class NavigationToolbar2QT(NavigationToolbar2, QtWidgets.QToolBar):
    toolitems = [*NavigationToolbar2.toolitems]
    toolitems.insert(
        # Add 'customize' action after 'subplots'
        [name for name, *_ in toolitems].index("Subplots") + 1,
        ("Customize", "Edit axis, curve and image parameters",
         "qt4_editor_options", "edit_parameters"))

    def __init__(self, canvas, parent=None, coordinates=True):
        """coordinates: should we show the coordinates on the right?"""
        QtWidgets.QToolBar.__init__(self, parent)
        self.setAllowedAreas(QtCore.Qt.ToolBarArea(

Review comment (suggestion):
Also here
```suggestion
        if self.is_dark_mode():
```

Code after:
        """
        large_path = base_path.with_name(base_path.stem + '_large.png')
        source_pixmap = QtGui.QPixmap()
        for candidate in (large_path, base_path):
            if not candidate.exists():
                continue
            candidate_pixmap = QtGui.QPixmap(str(candidate))
            if not candidate_pixmap.isNull():
                source_pixmap = candidate_pixmap
                break
        if source_pixmap.isNull():
            return source_pixmap

        dpr = self._devicePixelRatio()

        # Scale to requested size
        scaled_size = QtCore.QSize(int(size.width() * dpr), int(size.height() * dpr))
        scaled_pixmap = source_pixmap.scaled(
            scaled_size,
            QtCore.Qt.AspectRatioMode.KeepAspectRatio,
            QtCore.Qt.TransformationMode.SmoothTransformation
        )
        scaled_pixmap.setDevicePixelRatio(dpr)

        if self._is_dark_mode():
            # On some platforms (e.g., macOS with Qt5 in dark mode), this may
            # incorrectly return a black color instead of a light one.
            # See issue #27590 for details.
            icon_color = self.toolbar.palette().color(self.toolbar.foregroundRole())
            mask = scaled_pixmap.createMaskFromColor(
                QtGui.QColor('black'),
                QtCore.Qt.MaskMode.MaskOutColor)
            scaled_pixmap.fill(icon_color)
            scaled_pixmap.setMask(mask)

        return scaled_pixmap


class NavigationToolbar2QT(NavigationToolbar2, QtWidgets.QToolBar):
    toolitems = [*NavigationToolbar2.toolitems]
    toolitems.insert(
        # Add 'customize' action after 'subplots'
        [name for name, *_ in toolitems].index("Subplots") + 1,
        ("Customize", "Edit axis, curve and image parameters",
         "qt4_editor_options", "edit_parameters"))

    def __init__(self, canvas, parent=None, coordinates=True):
        """coordinates: should we show the coordinates on the right?"""
        QtWidgets.QToolBar.__init__(self, parent)
        self.setAllowedAreas(QtCore.Qt.ToolBarArea(
            _to_int(QtCore.Qt.ToolBarArea.TopToolBarArea) |