How to color arc in Qt?
-
I have a QGraphicsItem which is made of Line, Arc's and Circle. I have drawn a digital gate XNOR using arcs and lines and circles and colored it with blue color.
So when I initially load it looks like this:But when I click somewhere else, arc's color gets disappeared. And it looks like this:
I have colored it like this:
class myPoly: public QGraphicsPathItem { public: explicit myPoly(); myPoly(QPainterPath p) : QGraphicsPathItem(p) {} } //Drawing Arc for (unsigned int i = 0; i < iter->second._allArcs.size(); i++) { // getting 6 co-ordinates for Arc QPointF from(first, second); QPointF to(third, fourth); QPointF center(fifth, sixth); QLineF lineFrom{center, from}; QLineF lineTo{center, to}; qreal radius = lineFrom.length(); QRectF bounding{center - QPointF{radius, radius}, center + QPointF{radius, radius}}; QRectF bounding1(bounding.x() + x, bounding.y() + y, bounding.width(),bounding.height()); // Use QLineF to calculate angles wrt horizontal axis. qreal startAngle = lineFrom.angle(); qreal sweep = lineFrom.angleTo(lineTo); QPainterPath path; path.moveTo(from.x(), from.y()); path.arcTo(bounding1, startAngle, sweep); myPoly* poly = new myPoly(path); poly->createArc(); scene->addItem(static_cast<QGraphicsPathItem*>(poly)); } class myLine: public QGraphicsLineItem { public: myLine(); myLine(int x1,int y1,int x2 ,int y2,QGraphicsItem *parent = nullptr) : QGraphicsLineItem(x1,y1,x2,y2,parent) {} void DrawLine(); }; // Drawing line for (unsigned int i = 0; i < iter->second._allLines.size(); i++) { // getting 4 co-ordinates of lines. myLine* line = new myLine(first,second,third,fourth); line->DrawLine(); scene->addItem(static_cast<QGraphicsLineItem*>(line)); } void myLine::DrawLine() { this->setPen(QPen(QColor("blue"), 1)); } void myPoly::createArc() { QPen mPen; mPen.setWidth(1); mPen.setBrush(Qt::blue); this->setPen(mPen); }
Why this is happening ? And how to avoid it ?