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. Draw a head arrow
Forum Update on Monday, May 27th 2025

Draw a head arrow

Scheduled Pinned Locked Moved Unsolved General and Desktop
arrowdrawscene
2 Posts 2 Posters 12.4k 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.
  • AlvaroSA Offline
    AlvaroSA Offline
    AlvaroS
    wrote on last edited by AlvaroS
    #1

    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 active

    And if I change this line QPainter painter(ui->graphicsview); to QPainter painter(this);
    it has not errors but it does not paint anything...

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      The sample
      http://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html
      has arrow class.
      Maybe it can provide inspiration.

      1 Reply Last reply
      1

      • Login

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