void DrawShapes(QPainter painter) { painter.SetRenderHint(QPainter.RenderHint.Antialiasing); painter.Pen = new QPen(new QBrush(new QColor("Gray")), 1); painter.Brush = new QColor("Gray"); var path = new QPainterPath(); path.MoveTo(5, 5); path.CubicTo(40, 5, 50, 50, 99, 99); path.CubicTo(5, 99, 50, 50, 5, 5); painter.DrawPath(path); painter.DrawPie(130, 20, 90, 60, 30 * 16, 120 * 16); painter.DrawChord(240, 30, 90, 60, 0, 16 * 180); var rectangle = new QRect(new QPoint(20, 120), new QSize(80, 50)); painter.DrawRoundedRect(rect: rectangle, xRadius: 10, yRadius: 10); // to be implemented //var points = new List<QPoint>(); //points.Add ( new QPoint ( 130, 140 ) ); //points.Add ( new QPoint ( 180, 170 ) ); //points.Add ( new QPoint ( 180, 140 ) ); //points.Add ( new QPoint ( 220, 110 ) ); //points.Add ( new QPoint ( 140, 100 ) ); //// http://doc.qt.io/qt-5/qpolygon.html#QPolygon-2 , we should be able to pase point list //var polygon = new QPolygon(points); //painter.DrawPolygon ( polygon ); // this is workaround for DrawPolygon unsafe { var polygon = new QPolygon(); var points = new int[] { 130, 140, 180, 170, 180, 140, 220, 110, 140, 100 }; fixed(int *point = points) { polygon.SetPoints(points.Length / 2, ref *point); } painter.DrawPolygon(polygon); } painter.DrawRect(250, 110, 60, 60); var baseline = new QPointF(20, 250); var font = new QFont("Georgia", 55); var forntPath = new QPainterPath(); forntPath.AddText(baseline, font, "Q"); painter.DrawPath(forntPath); painter.DrawEllipse(140, 200, 60, 60); painter.DrawEllipse(240, 200, 90, 60); }
public override void Paint(QPainter painter, QStyleOptionGraphicsItem option, QWidget widget) { // Body painter.SetBrush(color); painter.DrawEllipse(-10, -20, 20, 40); // Eyes painter.SetBrush(Qt.GlobalColor.white); painter.DrawEllipse(-10, -17, 8, 8); painter.DrawEllipse(2, -17, 8, 8); // Nose painter.SetBrush(Qt.GlobalColor.black); painter.DrawEllipse(new QRectF(-2, -22, 4, 4)); // Pupils painter.DrawEllipse(new QRectF(-8.0 + mouseEyeDirection, -17, 4, 4)); painter.DrawEllipse(new QRectF(4.0 + mouseEyeDirection, -17, 4, 4)); // Ears painter.SetBrush(Scene().CollidingItems(this).Count == 0 ? Qt.GlobalColor.darkYellow : Qt.GlobalColor.red); painter.DrawEllipse(-17, -12, 16, 16); painter.DrawEllipse(1, -12, 16, 16); // Tail QPainterPath path = new QPainterPath(new QPointF(0, 20)); path.CubicTo(-5, 22, -5, 22, 0, 25); path.CubicTo(5, 27, 5, 32, 0, 30); path.CubicTo(-5, 32, -5, 42, 0, 35); painter.SetBrush(Qt.BrushStyle.NoBrush); painter.DrawPath(path); }
public override void Paint(QPainter painter, QStyleOptionGraphicsItem option, QWidget widget) { painter.SetBrush(Qt.GlobalColor.gray); painter.DrawRect(-20, -58, 40, 2); // front axel painter.DrawRect(-20, 7, 40, 2); // rear axel painter.SetBrush(color); painter.DrawRect(-25, -79, 50, 10); // front wing painter.DrawEllipse(-25, -48, 50, 20); // side pods painter.DrawRect(-25, -38, 50, 35); // side pods painter.DrawRect(-5, 9, 10, 10); // back pod painter.DrawEllipse(-10, -81, 20, 100); // main body painter.DrawRect(-17, 19, 34, 15); // rear wing painter.SetBrush(Qt.GlobalColor.black); painter.DrawPie(-5, -51, 10, 15, 0, 180 * 16); painter.DrawRect(-5, -44, 10, 10); // cocpit painter.Save(); painter.Translate(-20, -58); painter.Rotate(wheelsAngle); painter.DrawRect(-10, -7, 10, 15); // front left painter.Restore(); painter.Save(); painter.Translate(20, -58); painter.Rotate(wheelsAngle); painter.DrawRect(0, -7, 10, 15); // front left painter.Restore(); painter.DrawRect(-30, 0, 12, 17); // rear left painter.DrawRect(19, 0, 12, 17); // rear right }
void DrawDonut(QPainter painter) { var color = new QColor(); color.SetNamedColor("#333333"); painter.Pen = new QPen(color, 0.5); painter.SetRenderHint(QPainter.RenderHint.Antialiasing); painter.Translate(new QPoint(Width / 2, Height / 2)); for (double rot = 0; rot < 360.0; rot += 5.0) { painter.DrawEllipse(-125, -40, 250, 80); painter.Rotate(5.0); } }