Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to color arc in Qt?

How to color arc in Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 216 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tushu
    wrote on last edited by
    #1

    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:

    a1.PNG

    But when I click somewhere else, arc's color gets disappeared. And it looks like this:
    a2.PNG

    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 ?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved