def METHOD_NAME(self, painter: QPainter, rect: QRect, colors) -> None:
    job_nr = len(colors)
    grid_dim = math.ceil(math.sqrt(job_nr))
    k = 0
    colors_hash = hash(tuple(color.name() for color in colors))
    if colors_hash not in _image_cache:
        foreground_image = QImage(grid_dim, grid_dim, QImage.Format_ARGB32)
        foreground_image.fill(QColorConstants.Gray)
        for y in range(grid_dim):
            for x in range(grid_dim):
                if k >= job_nr:
                    color = QColorConstants.Gray
                else:
                    color = colors[k]
                foreground_image.setPixel(x, y, color.rgb())
                k += 1
        _image_cache[colors_hash] = foreground_image
    else:
        foreground_image = _image_cache[colors_hash]
    painter.drawImage(rect, foreground_image)