kullanın QPainter
bu işi yapmak için.
# Create a place to draw the circles.
circles = QImage(700, 700, QImage.Format_ARGB32)
# Init the painter
p = QPainter(circles)
# DestinationOver results in the current painting
# going below the existing image.
p.setCompositionMode(QPainter.CompositionMode_DestinationOver)
p.setRenderHints(QPainter.HighQualityAntialiasing)
p.setBrush(Qt.white)
p.setPen(QPen(Qt.green, 3.0))
# Paint the images in the PROPER order: 1, 2, 3, etc
p.drawEllipse(QPoint(300, 300), 200, 200)
p.drawEllipse(QPoint(450, 450), 100, 100)
p.drawEllipse(QPoint(300, 450), 150, 150)
p.end()
# The above image is transparent. If you prefer to have
# a while/color bg do this:
final = QImage(700 ,700, QImage.Format_ARGB32)
final.fill(Qt.lightgray)
p = QPainter(final)
# Now we want the current painting to be above the existing
p.setCompositionMode(QPainter.CompositionMode_SourceOver)
p.setRenderHints(QPainter.HighQualityAntialiasing)
p.drawImage(QRect(0, 0, 700, 700), circles)
p.end()
# Save the file.
final.save("/tmp/trial.png")
Doğrudan bir widget'ı boyamak için aynı kodu kullanabiliriz. Widget durumunda, ::paintEvent(QPaintEvent*)
'u geçersiz kılın ve bu işi yapın.
Her daireyi beyaz renkle doldurun. – CroCo
@CroCo ancak bir sonraki dairenin sınırı bir önceki döneme göre çizilecek, değil mi? – AnatoliySultanov
Saydam değilse, beyaz daire ve istediğiniz herhangi bir renkli kalemle – Apin