Source code:
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsEllipseItem>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.setSceneRect( 0.0, 0.0, 200.0, 200.0 );
QBrush whiteBrush(Qt::white);
QBrush blackBrush(Qt::black);
QPen blackPen(Qt::black);
blackPen.setWidth(3);
QPen whitePen(Qt::white);
whitePen.setWidth(3);
scene.addEllipse(0,0,200,200,blackPen,blackBrush); //big circle
QPainterPath rightWhiteSemicirclePath;
rightWhiteSemicirclePath.arcMoveTo(0+3, 0+3, 200-2*3, 200-2*3, 90);
rightWhiteSemicirclePath.arcTo(0+3, 0+3, 200-2*3, 200-2*3, 90, -180);
scene.addPath(rightWhiteSemicirclePath,whitePen,whiteBrush);
QPainterPath leftUpperSmallWhiteSemicirclePath;
//circle contains in the square shape
//square length is 100-3=97
//move the small square x position left (1/4*200)+3=53 pixels
leftUpperSmallWhiteSemicirclePath.arcMoveTo(50+3, 0+3, 100-3, 100-3, -90);
leftUpperSmallWhiteSemicirclePath.arcTo(50+3, 0+3, 100-3, 100-3, -90, -180);
scene.addPath(leftUpperSmallWhiteSemicirclePath,whitePen,whiteBrush);
QPainterPath rightLowerSmallBlackSemicirclePath;
rightLowerSmallBlackSemicirclePath.arcMoveTo(53-3, 100+3, 100-3, 100-3, 90);
rightLowerSmallBlackSemicirclePath.arcTo(53-3, 100+3, 100-3, 100-3, 90, -180);
scene.addPath(rightLowerSmallBlackSemicirclePath,blackPen,blackBrush);
scene.addEllipse(100-12.5, 50-12.5, 25, 25, blackPen, blackBrush); //small black upper circle
scene.addEllipse(100-12.5, 150-12.5, 25, 25, whitePen, whiteBrush); //small white lower circle
QGraphicsView view( &scene );
view.setFixedSize(300,300);
view.setWindowTitle("My Yin Yang Symbol");
view.show();
return app.exec();
}
Result:
☯
No comments:
Post a Comment