I'm drawing triangles/polygons in QPainter using antialiasing, which come from the rendering of 3D models. If two polygons are drawn immediately next to each other there is a gap between them.
Here is some code (in PyQt) to demonstrate the issue:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Window(QLabel):
def __init__(self):
QLabel.__init__(self)
pixmap = QPixmap(300,300)
pixmap.fill()
painter = QPainter(pixmap)
painter.setRenderHint(QPainter.Antialiasing)
painter.setPen(QPen(Qt.NoPen))
painter.setBrush(QBrush(QColor('black')))
poly1 = QPolygonF()
for x, y in ((0,0),(0,240.5),(210.3,0)):
poly1 << QPointF(x,y)
painter.drawPolygon(poly1)
poly2 = QPolygonF()
for x, y in ((210.3,0),(210.3,240),(0,240.5)):
poly2 << QPointF(x,y)
painter.drawPolygon(poly2)
painter.end()
self.setPixmap(pixmap)
app = QApplication(sys.argv)
win = Window()
win.show()
app.exec_()
How can I prevent this problem? As suggest below by vahancho, I could add borders to each polygon, or I could grow by half a pixel in each direction. Unfortunately this makes the joins visible if the fill/pen is partially transparent.