2016-06-22 2 views
5

Apple Retina 디스플레이에 대한 지원이 PyQt5 응용 프로그램에 추가됩니다. 나는 성공적으로 (내 모든 .png 파일에 2 배 @ 접미사를 추가하고 내 QApplicationQt.AA_UseHighDpiPixmaps를 설정하여) 고해상도 아이콘을 렌더링하기 위해 관리하는 동안, 나는 QGraphicsScene + QGraphicsView 높은 해상도를 QGraphicsItem 렌더링 몇 가지 문제가 있어요. 내 응용 프로그램에서Apple Retina 디스플레이의 QGraphicsItem 렌더링

, 다른 .png 파일을로드하는 것보다, 나 또한 여러 QPixmap 내 자신의 사용자가 QGraphicsView 렌더링 그림을 새로운 모양을 추가하는 데 사용할 수있는 기호 팔레트를 구축, (A Icon로를 내장)를 생성 예 :

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 

내 팔레트 (다이아몬드 하나)에 기호 중 하나가 생성됩니다. ,

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) 

Eddy Diagram

모양 내의 텍스트가 제대로 렌더링 :

Eddy Palette

그러나 나는 그들이 낮은 해상도에서 렌더링되는 QGraphicsView에 표시 내 QGraphicsScene에 요소를 추가 할 때 내 QGraphicsItem을 부모로 가지고있는 QGraphicsTextItem이므로 그림을 그려 본 것이 아닙니다.

문제는 QPixmap에 대해 기기의 픽셀 비율을 설정할 수 있지만 QGraphicsItem에 대해 할 수 없습니다. 내가 놓친 게 있니?

저는 이미 PyQt 개발자에게보고 한 응용 프로그램 시작시 여러 가지 충돌이 발생하기 때문에 Qt 5.5.1 및 SIP 4.18 용 PyQt 5.5.1 (5.6 사용하지 않음)을 사용하고 있습니다.

답변

0

아마도 당신이 듣고 싶지는 않지만 Qt added retina support in 5.6 일 것입니다.

+0

Qt 5.5/5.6에서 높은 DPI 지원에 관한 뉴스를 찾고 있었지만 블로그 게시물을 놓친 것 같습니다. PyQt 5.6에서 수정을 기다려야 할 것 같습니다. –

+0

당신의 대답이 내 문제를 해결하지 못하더라도 (Qt의 최신 버전으로 업그레이드하지 않고서는 명백하게 해결할 수 없기 때문에) 나는 당신에게 노력에 대한 현상금을 줄 것이다. –

-1

또한 PyQt 5.7에서 비슷한 문제로 고민하고 있습니다.

당신이 QGraphicsItem 당신의 서브 클래스를 작성하는 경우, 페인트() 메소드에서 앤티 앨리어싱에 대한 힌트를 렌더링 설정하려고 :

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.setRenderHint(QPainter.Antialiasing) # <-- add this line 
    painter.drawPolygon(self.polygon) 

주, 이것은 최선의 또는 정확한 답하지 않을 수 있습니다.

관련 문제