Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

Dots while freehand drawing on QGraphicsView and Problem while remove items from QGraphicsView.

$
0
0
Hi, I want to draw freehand drawing on QGraphicsView. I am able to draw it. But, when the line draw on QGraphicsView, it also create small small dots. How can i remove these dots ? I am sharing code of mouse press, mouse move and mouse release on QGraphicsView and line draw function where i am adding the line on QGraphicsScene which is associated with QGraphicsView. The following code also contains code for Eraser. Eraser is also works but it also remove items which are out of Eraser’s area. void WhiteBoardView::mousePressEvent (QMouseEvent *event) {     if(event->button() == Qt::LeftButton)     {         vbMousePressed = true;           if(vbPenSelected)         {             /* This code will execute when Pen is selected */               currntPt = previousPt = mapToScene(event->pos());                   drawLineTo(previousPt,currntPt,vPenForDrawing);         }         else if(vbEraserSelected)         {             /* This code will execute when Eraser is selected */               rad = vRadiusForEarser;             pt = mapToScene(event->pos());               EraserLineTo(pt, rad);         }         } }     void WhiteBoardView::mouseMoveEvent (QMouseEvent *event) {     vbMouseMoving = true;       if(vbMousePressed && vbMouseMoving)     {         if(vbPenSelected)         {             /* This code will execute when Pen is selected */               previousPt = currntPt;             currntPt = mapToScene(event->pos());             drawLineTo(previousPt,currntPt,vPenForDrawing);         }         else if(vbEraserSelected)         {             /* This code will execute when Eraser is selected */               rad = vRadiusForEarser;             pt = mapToScene(event->pos());               EraserLineTo(pt, rad);           }       }   }   void WhiteBoardView::mouseReleaseEvent (QMouseEvent *event) {     Q_UNUSED(event);       if(vbMouseMoving)     {         if(vbPenSelected)         {           }           else if(vbEraserSelected)         {             /* Following code is used to remove items from QGraphicsScene  */               mWhiteBoardScene->addEllipse(pt.x()-rad, pt.y()-rad, rad*2.0, rad*2.0,QPen(Qt::blue), QBrush(Qt::transparent));             listOfItems = mWhiteBoardScene->items(pt.x()-rad, pt.y()-rad, rad*2.0, rad*2.0, Qt::IntersectsItemShape);               for(int i=0; i < listOfItems.size(); i++)             {                 mWhiteBoardScene->removeItem(listOfItems[i], true);                 delete listOfItems[i];             }                 listOfItems.clear();         }           vbMouseMoving = false;         vbMousePressed = false;     } }   /* Following function is used to draw line on QGraphicsScene  */   void WhiteBoardView::drawLineTo(const QPointF &previous, const QPointF &current, const QPen& drawPen) {     mWhiteBoardScene->addLine(previous.x(), previous.y(), current.x(), current.y(), drawPen); }   /* Following function is used to Remove Items from QGraphicsScene  */   void WhiteBoardView::EraserLineTo(const QPointF &current, double radius) {       listOfItems = mWhiteBoardScene->items(current.x()-radius, current.y()-radius, radius*2.0, radius*2.0, Qt::IntersectsItemShape);       for(int i=0; i < listOfItems.size(); i++)     {         mWhiteBoardScene->removeItem(listOfItems[i], true);         delete listOfItems[i];     }       mWhiteBoardScene->addEllipse(current.x()-radius, current.y()-radius, radius*2.0, radius*2.0,QPen(Qt::blue), QBrush(Qt::transparent));   } Thanks in advance …

Viewing all articles
Browse latest Browse all 18427

Trending Articles