M
M
Matweytt2019-05-29 12:07:33
Qt
Matweytt, 2019-05-29 12:07:33

How to visualize an edge of a QT graph?

There is a task to visualize the graph. Everything is fine with the vertices, but there is a problem with the edge, I don’t know how to make an arrow from QGraphicsLineItem. The code below takes the coordinates of the vertex from which the arrow should be built, then the coordinates of the vertex where the arrow should be built and the name of the edge. But he just draws a line, but you need a line with an arrow. How to implement????
void MainWindow::getrebro(float x, float y, float xx, float yy, QString s)
{
QGraphicsLineItem *line = new QGraphicsLineItem(x+5,y+5,xx+5,yy+5);
line->setZValue(-1);
float xt = (x+xx)/2;
float yt = (y+yy)/2;
QGraphicsTextItem *text = new QGraphicsTextItem(s);
text->setX(xt);
text->setY(yt);
scene->addItem(line);
scene->addItem(text);
}
vertices are built like this:
void MainWindow::getsubject(float x, float y, QString s)
{
QGraphicsEllipseItem *ellips = new QGraphicsEllipseItem(0,0,10,10);
ellips->setY(y);
ellips->setX(x);
ellips->setBrush(Qt::black);
QGraphicsTextItem *text = new QGraphicsTextItem(s);
text->setY(y+5);
text->setX(x);
scene->addItem(ellipses);
scene->addItem(text);
}
void MainWindow::getobject(float x, float y, QString s)
{
QGraphicsEllipseItem *ellips = new QGraphicsEllipseItem(0,0,10,10);
ellips->setY(y);
ellips->setX(x);
ellips->setBrush(Qt::white);
QGraphicsTextItem *text = new QGraphicsTextItem(s);
text->setY(y+5);
text->setX(x);
scene->addItem(ellipses);
scene->addItem(text);
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2019-05-29
@vt4a2h

Write the drawing of the arrow yourself: https://doc.qt.io/qt-5/qtwidgets-graphicsview-diag...
Here is the whole example: https://doc.qt.io/qt-5/qtwidgets-graphicsview-diag ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question