Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Draw a head arrow

    General and Desktop
    arrow draw scene
    2
    2
    11195
    Loading More Posts
    • 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.
    • AlvaroS
      AlvaroS last edited by AlvaroS

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • First post
          Last post