Draw a head arrow
-
Hello everyone:
First of all thanks for helping me and reading this post.I have some items lines in a scene and now I would like to draw a head arrow in each line.
I have tried this with head arrows as Poligon and then add to the scene like this:QPolygonF head_arrow; for (.....) { .................. head_arrow << QPoint((lines_vector[i].x_end)-min_x,max_y-(lines_vector[i].y_end)); head_arrow << QPoint((lines_vector[i].x_end)-min_x-0.01,max_y-lines_vector[i].y_end+0.01*tan(30*3.14/180)); head_arrow << QPoint((lines_vector[i].x_end)-min_x-0.01,max_y-lines_vector[i].y_end-0.01*tan(30*3.14/180)); head_arrow << QPoint((lines_vector[i].x_end)-min_x,max_y-(lines_vector[i].y_end)); scene->addPolygon(head_arrow,black); ................
It compiles fine but the head arrows does not fit like my code...
is there any other way to do that or any ideas to fit my problem?thanks a lot.
EDIT:
I have tried with Qpaintevent as well like this:
void MainWindow::paintEvent(QPaintEvent *e) { QPainter painter(ui->graphicsview); QPolygonF head_arrow; QPen linepen; linepen.setWidthF(1); linepen.setColor(Qt::red); painter.setPen(linepen); for (int i=0;i<lines_vector.size();i++) { head_arrow << QPoint((lines_vector[i].x_end)-min_x,max_y-(lines_vector[i].y_end)); head_arrow << QPoint((lines_vector[i].x_end)-min_x-0.01,max_y-lines_vector[i].y_end+0.01*tan(30*3.14/180)); head_arrow << QPoint((lines_vector[i].x_end)-min_x-0.01,max_y-lines_vector[i].y_end-0.01*tan(30*3.14/180)); head_arrow << QPoint((lines_vector[i].x_end)-min_x,max_y-(lines_vector[i].y_end)); painter.drawPolygon(head_arrow); } }
It compiles fine but it says errors:
QWidget::paintEngine: Should no longer be called
QPainter::begin: Paint device returned engine == 0, type: 1
QPainter::setPen: Painter not activeAnd if I change this line QPainter painter(ui->graphicsview); to QPainter painter(this);
it has not errors but it does not paint anything... -
The sample
http://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html
has arrow class.
Maybe it can provide inspiration.