Apple Retina Display上的QGraphicsItem渲染

Dan*_*one 5 qt pyqt qgraphicsview qgraphicsitem retina-display

我正在为我的PyQt5应用程序添加对Apple Retina Display的支持.虽然我成功地设法渲染高分辨率图标(通过在我的所有文件中添加@ 2x后缀.png并设置Qt.AA_UseHighDpiPixmaps我的内容QApplication),但我QGraphicsItem在使用QGraphicsScene+ 渲染高分辨率时遇到了一些麻烦QGraphicsView.

在我的应用程序中,除了加载.png文件之外,我还生成了几个QPixmap我自己(将它们嵌入到a中Icon),以构建符号调色板,用户可以使用这些符号将新形状添加到呈现的图中QGraphicsView,即:

def icon(cls, width, height, **kwargs):
    """
    Returns an icon of this item suitable for the palette.
    :type width: int
    :type height: int
    :rtype: QIcon
    """
    icon = QIcon()
    for i in (1.0, 2.0):
        # CREATE THE PIXMAP
        pixmap = QPixmap(width * i, height * i)
        pixmap.setDevicePixelRatio(i)
        pixmap.fill(Qt.transparent)
        # PAINT THE SHAPE
        polygon = cls.createPolygon(46, 34)
        painter = QPainter(pixmap)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(QPen(QColor(0, 0, 0), 1.1, Qt.SolidLine))
        painter.setBrush(QColor(252, 252, 252))
        painter.translate(width / 2, height / 2)
        painter.drawPolygon(polygon)
        # PAINT THE TEXT INSIDE THE SHAPE
        painter.setFont(Font('Arial', 11, Font.Light))
        painter.drawText(polygon.boundingRect(), Qt.AlignCenter, 'role')
        painter.end()
        # ADD THE PIXMAP TO THE ICON
        icon.addPixmap(pixmap)
    return icon
Run Code Online (Sandbox Code Playgroud)

这会在我的调色板中生成一个符号(钻石一个).

艾迪调色板

但是当我向我添加元素时QGraphicsScene,显示在QGraphicsView它们中以低分辨率呈现:

def paint(self, painter, option, widget=None):
    """
    Paint the node in the diagram.
    :type painter: QPainter
    :type option: QStyleOptionGraphicsItem
    :type widget: QWidget
    """
    painter.setPen(self.pen)
    painter.setBrush(self.brush)
    painter.drawPolygon(self.polygon)
Run Code Online (Sandbox Code Playgroud)

艾迪图

形状中的文本是正确呈现的,我不是自己画的,因为它是QGraphicsTextItem我QGraphicsItem的父母.

问题是,虽然QPixmap我可以设置设备像素比率,因为QGraphicsItem我不能.我错过了什么吗?

我正在使用针对Qt 5.5.1和SIP 4.18构建的PyQt 5.5.1(不使用5.6,因为我在应用程序启动时遇到了几次崩溃,我已经向PyQt devs报告了).

bgp*_*000 0

可能不是您想听到的,但Qt 在 5.6 中添加了视网膜支持。