0
多くの円を連続して描く必要があります。私が次のサークルを描くとき、他のサークルとの交差点は隠されるべきです。サンプルコードを教えてください。Qtで特定の円を描く
On this picture firstly I draw "1" circle, then "2" circle, then "3" circle
多くの円を連続して描く必要があります。私が次のサークルを描くとき、他のサークルとの交差点は隠されるべきです。サンプルコードを教えてください。Qtで特定の円を描く
On this picture firstly I draw "1" circle, then "2" circle, then "3" circle
、この作業を行うにはQPainter
を使用してください。
# 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")
ウィジェットを直接ペイントするために同じコードを使用できます。ウィジェットの場合は、::paintEvent(QPaintEvent*)
をオーバーライドし、この作業を行います。
ありがとうございます! – AnatoliySultanov
各円を白色で塗りつぶします。 – CroCo
@CroCoしかし、次のサークルのボーダーは前のサークルに描かれますね。 – AnatoliySultanov
透明でない場合は、サークル3,2、および1を順番にすべての円に対して白色で塗りつぶします。 – Apin