Unsolved how can draw a line that is created from path mouse but the lines be broken vertical line?
-
hi, i want to between two object in graphicview created a line,that they are broken vertical and horizontal line.i created lines between two objects.
this is a part source example diagram scene:void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { if (myStartItem->collidesWithItem(myEndItem)) return; QPen myPen = pen(); myPen.setColor(myColor); qreal arrowSize = 20; painter->setPen(myPen); painter->setBrush(myColor); //! [4] //! [5] QLineF centerLine(myStartItem->pos(), myEndItem->pos()); QPolygonF endPolygon = myEndItem->polygon(); QPointF p1 = endPolygon.first() + myEndItem->pos(); QPointF p2; QPointF intersectPoint; QLineF polyLine; for (int i = 1; i < endPolygon.count(); ++i) { p2 = endPolygon.at(i) + myEndItem->pos(); polyLine = QLineF(p1, p2); QLineF::IntersectType intersectType = polyLine.intersect(centerLine, &intersectPoint); if (intersectType == QLineF::BoundedIntersection) break; p1 = p2; } setLine(QLineF(intersectPoint, myStartItem->pos())); //! [5] //! [6] double angle = ::acos(line().dx() / line().length()); if (line().dy() >= 0) angle = (Pi * 2) - angle; QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize, cos(angle + Pi / 3) * arrowSize); QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, cos(angle + Pi - Pi / 3) * arrowSize); arrowHead.clear(); arrowHead << line().p1() << arrowP1 << arrowP2; //! [6] //! [7] painter->drawLine(line()); painter->drawPolygon(arrowHead); if (isSelected()) { painter->setPen(QPen(myColor, 1, Qt::DashLine)); QLineF myLine = line(); myLine.translate(0, 4.0); painter->drawLine(myLine); myLine.translate(0,-8.0); painter->drawLine(myLine); }
see below image:
http://www.mediafire.com/view/5apc35l064pd4kp/brokenline.png
i want to it is same broken line same matlabsimulink...below image
http://www.mediafire.com/view/z1axz5p7tmlqx8d/linebroken2(2).png#thanks for reply
-
anyone doesn't any idea>please help me
thanks for reply.
-
Hi @stackprogramer ,
I have example code for drawing the Dash lines/ dash dot line/ dash dot sot lines. It is example, copied from internet and some of my code. Please download it here. . It draws the line basing on the mouse press, move and release. You can change the origin and last postion in this cide and can use as you wish. I did not set any toolbar menu to give the DashLine/DashDotLine/DashDotDotLine. I just hard coded it. Fin it in the scene.cpp at line "itemToDraw->setPen(QPen(Qt::black, 3, Qt::DashLine));" in void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) function.
Hopefully, it solves your problem.
-
thanks but i want to broken line ,direct line example i had.