#!/usr/bin/env python

# from PyQt4.Qt import *
# from PyQt4.QtCore import *
# from PyQt4.QtGui import *

from PyQt5.Qt import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

def createPixmap():
    polygon = QPolygon()
    polygon << QPoint(70, -351) << QPoint(170, -251) << QPoint(503, -19) \
      << QPoint(503, 217)
    image = QImage(800, 300, QImage.Format_RGB32)
    painter = QPainter(image)
    painter.setPen(QPen(Qt.white, 2))
    painter.drawPolyline(polygon)
    painter.setPen(QPen(Qt.red, 0))
    painter.drawPolyline(polygon)
    painter.end()
    return QPixmap.fromImage(image)

def rotate(p, angle):
    transform = QTransform()
    transform.rotate(angle)
    return transform.map(p)

def createPixmap2():
    a = QPolygon()
    # a.setPoints([2, 0, 0, -2,
    #              -2, 0, -2, 1,
    #              0, -1, 2, 1])
    m = 0
    a.setPoints([3 + m, 1 + m, 0, -2,
                 -(3 + m), 1 + m, -(3 + m), 2 + m,
                 -(2 + m), 2 + m, 0, 0,
                 2 + m, 2 + m, 3 + m, 2 + m])
    image = QImage(100, 100, QImage.Format_RGB32)
    image.fill(QColor(Qt.gray).rgb())
    for i in range(4):
        b = rotate(a, 90 * i)
        b.translate(10 * (i + 1), 10);
        p = QPainter(image)
        # p.setRenderHint(QPainter.Antialiasing, True)
        p.setPen(Qt.black)
        p.setBrush(Qt.black)
        p.drawPolyline(b)
        path = QPainterPath()
        path.addPolygon(QPolygonF(b))
        p.fillPath(path, Qt.black)
        p.end()
    return QPixmap.fromImage(image)

def main():
    import sys
    app = QApplication(sys.argv)
    label = QLabel()
    label.setPixmap(createPixmap2())
    label.show()
    return app.exec_()

if __name__ == '__main__':
    main()
