2016-03-25 12 views
0

ile çizim Sırasıyla çok sayıda daire çizmem gerekiyor. Bir sonraki çemberi çizdiğimde, başkalarıyla kesişme gizlenmelidir. Lütfen bana bir örnek kod verin.Belirli çevreleri Qt

On this picture firstly I draw "1" circle, then "2" circle, then "3" circle

+0

Her daireyi beyaz renkle doldurun. – CroCo

+0

@CroCo ancak bir sonraki dairenin sınırı bir önceki döneme göre çizilecek, değil mi? – AnatoliySultanov

+0

Saydam değilse, beyaz daire ve istediğiniz herhangi bir renkli kalemle – Apin

cevap

0

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.

+0

Çok teşekkür ederim! – AnatoliySultanov